2025-06-21, 22:10
Für ein kleines Projekt brauchte ich die Möglichkeit, flexible Zahlungspläne zu erzeugen. Der folgende Python-Code tut genau das.
import pandas as pd
from datetime import datetime
from dateutil.relativedelta import relativedelta
def genPaymentPlan(contract, principal, paymentsperyear, interestrate, startdate, years):
interest = interestrate/100*principal/paymentsperyear
date = datetime.strptime(startdate, '%Y-%m-%d').date()
output = pd.DataFrame(columns=['Contract', 'Date', 'Amount'])
# Add a row to the DataFrame
start = {'Contract': contract, 'Date': startdate, 'Amount' : principal}
output = pd.concat([output, pd.DataFrame([start])], ignore_index=True)
for payment in range(paymentsperyear*years):
new_date = (date + relativedelta(months=12/paymentsperyear))
date = new_date
interest_line = {'Contract': contract, 'Date': new_date.strftime('%Y-%m-%d'), 'Amount' : -1*interest}
output = pd.concat([output, pd.DataFrame([interest_line])], ignore_index=True)
end = {'Contract': contract, 'Date': date, 'Amount' : -principal}
output = pd.concat([output, pd.DataFrame([end])], ignore_index=True)
return output
test = genPaymentPlan(123456, 100, 4, 12, '2025-01-01', 4)
print(test) |
import pandas as pd
from datetime import datetime
from dateutil.relativedelta import relativedelta
def genPaymentPlan(contract, principal, paymentsperyear, interestrate, startdate, years):
interest = interestrate/100*principal/paymentsperyear
date = datetime.strptime(startdate, '%Y-%m-%d').date()
output = pd.DataFrame(columns=['Contract', 'Date', 'Amount'])
# Add a row to the DataFrame
start = {'Contract': contract, 'Date': startdate, 'Amount' : principal}
output = pd.concat([output, pd.DataFrame([start])], ignore_index=True)
for payment in range(paymentsperyear*years):
new_date = (date + relativedelta(months=12/paymentsperyear))
date = new_date
interest_line = {'Contract': contract, 'Date': new_date.strftime('%Y-%m-%d'), 'Amount' : -1*interest}
output = pd.concat([output, pd.DataFrame([interest_line])], ignore_index=True)
end = {'Contract': contract, 'Date': date, 'Amount' : -principal}
output = pd.concat([output, pd.DataFrame([end])], ignore_index=True)
return output
test = genPaymentPlan(123456, 100, 4, 12, '2025-01-01', 4)
print(test)
2025-06-12, 22:15
Hier ein wenig TikZ-Code, um Drumpatterns für einen Drumcomputer mit TikZ zu zeichnen. Das Beispiel ist für eine Spur, es lassen sich aber beliebig viele Spuren untereinandersetzen.
%!TEX TS-program = Arara
% arara: lualatex: {shell: no}
\documentclass{scrartcl}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Define the pattern as a comma-separated list
\def\pattern{x,-,x,x,-,x,x,-,-,-,x,x,-,-,-,x}
\def\cellsizex{1cm}
\def\cellsizey{0.5cm}
%\draw (0,0) rectangle ++ (\cellsizex-1, \cellsizey);
\node[draw, rectangle,minimum width = \cellsizex, align=left,minimum height=\cellsizey] (a) at (\cellsizex/2,\cellsizey/2){1};
% Loop through each character in the pattern
\foreach \cell [count=\index from 1] in \pattern {
% If 'x' fill the cell, otherwise leave it empty
\if\cell x
\fill[gray,draw=black] ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
\else
\draw ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
\fi
}
\end{tikzpicture}
\end{document} |
%!TEX TS-program = Arara
% arara: lualatex: {shell: no}
\documentclass{scrartcl}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Define the pattern as a comma-separated list
\def\pattern{x,-,x,x,-,x,x,-,-,-,x,x,-,-,-,x}
\def\cellsizex{1cm}
\def\cellsizey{0.5cm}
%\draw (0,0) rectangle ++ (\cellsizex-1, \cellsizey);
\node[draw, rectangle,minimum width = \cellsizex, align=left,minimum height=\cellsizey] (a) at (\cellsizex/2,\cellsizey/2){1};
% Loop through each character in the pattern
\foreach \cell [count=\index from 1] in \pattern {
% If 'x' fill the cell, otherwise leave it empty
\if\cell x
\fill[gray,draw=black] ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
\else
\draw ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
\fi
}
\end{tikzpicture}
\end{document}

drumbrute_pattern2.pdf
2025-06-08, 19:02
Hier ein kurzes Windows Batch-Skript, das alle PDFs mit dem Namensschema pg_*
in PNGs umwandelt. pdftoppm
ist Teil von poppler und muss installiert sein.
Ich nutze das, um PDF-Präsentationen — die ich vorher mit pdftk dateiname.pdf burst
in einzelne PDFs zerlegt hatte — nach PNG zu wandeln.
@echo off
setlocal enabledelayedexpansion
REM Set the output image format (e.g., png, jpeg, or ppm)
set FORMAT=png
REM Loop through all PDF files in the current directory
for %%F in (pg*.pdf) do (
echo Converting %%F...
pdftoppm -%FORMAT% "%%F" "%%~nF"
)
echo Done!
pause
Category:
Allgemein |
Kommentare deaktiviert für Alle PDFs in einem Verzeichnis nach PNG verwandeln
2025-06-08, 12:15
Ausgehend von einer Frage im LaTeX Reddit-Forum hier die Antwort, wie man mit Tikz „unscharfe“ Kreise zeichnen kann.
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade[inner color = gray, outer color = white] (0,0) circle [radius = 1];
\end{tikzpicture}
\end{document} |
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade[inner color = gray, outer color = white] (0,0) circle [radius = 1];
\end{tikzpicture}
\end{document}

2025-04-21, 08:48
Hier der preprint meines neuen Artikels für die TeXnische Komödie.
UweZiegenhagen-Ulam.pdf
ulam_500.pdf (16 MB)
Category:
LaTeX,
Artikel |
Kommentare deaktiviert für Ulam Spiralen mit TikZ und Lualatex
2025-04-13, 21:43
Mit dem folgenden Skript kann man alle PDFs eines Verzeichnisses nach PNG wandeln. Poppler muss dazu installiert und im Pfad sein.
@echo off
setlocal enabledelayedexpansion
REM Set the output image format (e.g., png, jpeg, or ppm)
set FORMAT=png
REM Loop through all PDF files in the current directory
for %%F in (pg*.pdf) do (
echo Converting %%F...
pdftoppm -%FORMAT% "%%F" "%%~nF"
)
echo Done!
pause
Category:
LaTeX |
Kommentare deaktiviert für Mit einer Batch-Datei alle PDF Dateien nach PNG umwandeln
2025-03-15, 21:35
Mit dem listofitems
-Paket lassen sich recht einfach „for jeden Eintrag in Liste“ Schleifen in LaTeX umsetzen. Hier ein Beispiel für das Setzen einer 10m Zielscheibe für Luftpistolen mit TikZ.
\documentclass[tikz,border=0.5cm]{standalone}
\usetikzlibrary{positioning}
\renewcommand\familydefault{\sfdefault}
\usepackage{listofitems}
\setsepchar{;}
\begin{document}
\begin{tikzpicture}[font=\bfseries,thick]
%\draw[step=0.5cm,lightgray,thin] (0,0) grid (16,16);
\coordinate (o) at (8,8);
\draw[black,thick,fill=lightgray] (8,8) circle (29.75mm);
\readlist\distances{77.5;69.75;61.75;53.75;45.75;37.75;21.75;13.75;5.75}
\foreachitem\distance\in\distances{
\draw[black] (8,8) circle (\distance mm);
}
\readlist\distances{7.1;6.3;5.5;4.7;3.9;3.1;2.3;1.5;0.7}
\readlist\directions{right;above;left;below}
\foreachitem\direction\in\directions{
\foreachitem\distance\in\distances{
\node[\direction=\distance cm of o] {\distancecnt};
}
}
\end{tikzpicture}
\end{document} |
\documentclass[tikz,border=0.5cm]{standalone}
\usetikzlibrary{positioning}
\renewcommand\familydefault{\sfdefault}
\usepackage{listofitems}
\setsepchar{;}
\begin{document}
\begin{tikzpicture}[font=\bfseries,thick]
%\draw[step=0.5cm,lightgray,thin] (0,0) grid (16,16);
\coordinate (o) at (8,8);
\draw[black,thick,fill=lightgray] (8,8) circle (29.75mm);
\readlist\distances{77.5;69.75;61.75;53.75;45.75;37.75;21.75;13.75;5.75}
\foreachitem\distance\in\distances{
\draw[black] (8,8) circle (\distance mm);
}
\readlist\distances{7.1;6.3;5.5;4.7;3.9;3.1;2.3;1.5;0.7}
\readlist\directions{right;above;left;below}
\foreachitem\direction\in\directions{
\foreachitem\distance\in\distances{
\node[\direction=\distance cm of o] {\distancecnt};
}
}
\end{tikzpicture}
\end{document}
PDF
Lupi-10-1
Category:
Allgemein |
Kommentare deaktiviert für Foreach-Schleifen in LaTeX TikZ
2025-03-06, 21:24
Hier ein einfacher Code-Schnipsel, um aus CSV-Dateien Excel-Dateien zu machen.
Es empfiehlt sich auch, die Engine explizit zu setzen, mit der die Excel-Datei geschrieben wird. Standardmäßig nutzt pandas openpyxl, xlsxwriter scheint nach meinen Tests aber um ca. 30% schneller zu sein.
import pandas as pd
from openpyxl import Workbook
from openpyxl.utils.dataframe import dataframe_to_rows
# output control
files = ['']
wb = Workbook()
wb.remove(wb['Sheet'])
for index, file in enumerate(files,0):
temp = pd.read_csv(file + '.csv',sep='\t')
ws1 = wb.create_sheet()
ws1.title = file
rows = dataframe_to_rows(temp, index=False, header=True)
for r_idx, row in enumerate(rows, 1):
for c_idx, value in enumerate(row, 1):
ws1.cell(row=r_idx, column=c_idx, value=value)
wb.save('files45646.xlsx')
wb.close() |
import pandas as pd
from openpyxl import Workbook
from openpyxl.utils.dataframe import dataframe_to_rows
# output control
files = ['']
wb = Workbook()
wb.remove(wb['Sheet'])
for index, file in enumerate(files,0):
temp = pd.read_csv(file + '.csv',sep='\t')
ws1 = wb.create_sheet()
ws1.title = file
rows = dataframe_to_rows(temp, index=False, header=True)
for r_idx, row in enumerate(rows, 1):
for c_idx, value in enumerate(row, 1):
ws1.cell(row=r_idx, column=c_idx, value=value)
wb.save('files45646.xlsx')
wb.close()
2025-02-27, 21:52
Aus aktuellem Anlass hier ein einfaches Beispiel, wie man Werte in pandas Dataframes ersetzen kann:
import pandas as pd
# initialize data of lists.
data = {'Hersteller': ['VW', 'BMW', 'VW', 'Porsche'],
'Modell': ['Golf', '1er', 'Polo', '911']}
df = pd.DataFrame(data)
print(df,'\n')
df['Hersteller'] = df['Hersteller'].replace(
{"VW": "Volkswagen", "Horch": "Audi"})
print(df) |
import pandas as pd
# initialize data of lists.
data = {'Hersteller': ['VW', 'BMW', 'VW', 'Porsche'],
'Modell': ['Golf', '1er', 'Polo', '911']}
df = pd.DataFrame(data)
print(df,'\n')
df['Hersteller'] = df['Hersteller'].replace(
{"VW": "Volkswagen", "Horch": "Audi"})
print(df)
2025-02-08, 18:29
Hier ein Code-Beispiel für die wichtigsten Funktionen von DuckDB.
import duckdb as ddb
import pandas as pd
con = ddb.connect(':memory:')
con_p = ddb.connect('my_database.db')
con_p.execute('CREATE OR REPLACE TABLE telefonnummern(fullname VARCHAR,phone VARCHAR);')
con_p.execute("INSERT INTO telefonnummern VALUES ('Max Mustermann', '0123-4567890')")
print(con_p.sql('SHOW ALL TABLES'))
print(con_p.sql('SELECT * FROM telefonnummern;'))
ddb_object = con_p.sql('SELECT * FROM telefonnummern;')
df = ddb_object.to_df()
ddb_tuple = ddb_object.fetchall()
print(df)
print(ddb_tuple) |
import duckdb as ddb
import pandas as pd
con = ddb.connect(':memory:')
con_p = ddb.connect('my_database.db')
con_p.execute('CREATE OR REPLACE TABLE telefonnummern(fullname VARCHAR,phone VARCHAR);')
con_p.execute("INSERT INTO telefonnummern VALUES ('Max Mustermann', '0123-4567890')")
print(con_p.sql('SHOW ALL TABLES'))
print(con_p.sql('SELECT * FROM telefonnummern;'))
ddb_object = con_p.sql('SELECT * FROM telefonnummern;')
df = ddb_object.to_df()
ddb_tuple = ddb_object.fetchall()
print(df)
print(ddb_tuple)