Fix dates on x axis
This commit is contained in:
parent
1dab0d748f
commit
dd9e44eace
@ -1,34 +1,48 @@
|
||||
import pandas as pd
|
||||
from banking_breakdown import document_builder
|
||||
import subprocess
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from banking_breakdown import types
|
||||
import numpy as np
|
||||
|
||||
|
||||
def main():
|
||||
def _generate_dummy_data() -> types.ReportData:
|
||||
categories = ["A", "B", "C", "D", "E", "F", "G"]
|
||||
values = np.array([10, 12, 53, 12, 90, 23, 32])
|
||||
values = values / values.sum() * 100
|
||||
|
||||
total_value = np.random.normal(size=10) + 4
|
||||
net_income = np.diff(total_value)
|
||||
values = np.round(values, decimals=1)
|
||||
values[-1] += 100 - np.sum(values)
|
||||
|
||||
category_overview_df = pd.DataFrame(
|
||||
{"category": categories, "value": values.astype('int32')})
|
||||
t = np.linspace(0, total_value.size, total_value.size)
|
||||
total_value_df = pd.DataFrame({"t": t, "value": total_value})
|
||||
t = np.linspace(0, net_income.size, net_income.size)
|
||||
{"category": categories, "value": values})
|
||||
|
||||
t = ["2023-01-01",
|
||||
"2023-02-01",
|
||||
"2023-03-01",
|
||||
"2023-04-01",
|
||||
"2023-05-01",
|
||||
"2023-06-01",
|
||||
"2023-07-01",
|
||||
"2023-08-01",
|
||||
"2023-09-01",
|
||||
"2023-10-01",
|
||||
"2023-11-01",
|
||||
"2023-12-01"]
|
||||
|
||||
net_income = 200 * np.random.normal(size=len(t)) + 100
|
||||
net_income_df = pd.DataFrame({"t": t, "value": net_income})
|
||||
|
||||
total_value = np.cumsum(net_income)
|
||||
|
||||
total_value_df = pd.DataFrame({"t": t, "value": total_value})
|
||||
|
||||
report_data = types.ReportData(category_overview=category_overview_df,
|
||||
net_income=net_income_df,
|
||||
total_value=total_value_df)
|
||||
|
||||
return report_data
|
||||
|
||||
|
||||
def main():
|
||||
report_data = _generate_dummy_data()
|
||||
document_builder.build_document(report_data)
|
||||
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
\usepackage{amsmath}
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{compat=newest}
|
||||
\usetikzlibrary{pgfplots.dateplot}
|
||||
|
||||
% Other packages
|
||||
\usepackage[a4paper, total={12cm, 25cm}]{geometry}
|
||||
@ -30,6 +31,10 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
\makeatletter
|
||||
\newcommand*\shortyear[1]{\expandafter\@gobbletwo\number\numexpr#1\relax}
|
||||
\makeatother
|
||||
|
||||
\newcommand{\slice}[6]{
|
||||
\pgfmathparse{0.5*#1+0.5*#2}
|
||||
\let\midangle\pgfmathresult
|
||||
@ -136,15 +141,28 @@
|
||||
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
date coordinates in=x,
|
||||
width=\textwidth,
|
||||
height=0.375\textwidth,
|
||||
ylabel={Net income in €},
|
||||
y label style={at={(-0.1,0.5)},anchor=south},
|
||||
xticklabel=\month.\shortyear{\year},
|
||||
xtick=data,
|
||||
xticklabel style={
|
||||
rotate=60,
|
||||
anchor=near xticklabel,
|
||||
},
|
||||
grid,
|
||||
]
|
||||
\addplot+[ybar, color=scol2, fill=scol2, line width=1pt]
|
||||
% Dummy plot to set x axis labels
|
||||
\addplot[draw=none]
|
||||
table[col sep=comma, x=t, y=value]
|
||||
{net_income.csv};
|
||||
|
||||
\addplot[ybar, color=scol2, fill=scol2, line width=1pt]
|
||||
table[col sep=comma, x=t, y=value, discard if lt={value}{0}]
|
||||
{net_income.csv};
|
||||
\addplot+[ybar, color=scol0, fill=scol0, line width=1pt]
|
||||
\addplot[ybar, color=scol0, fill=scol0, line width=1pt]
|
||||
table[col sep=comma, x=t, y=value, discard if gt={value}{0}]
|
||||
{net_income.csv};
|
||||
\end{axis}
|
||||
@ -155,11 +173,19 @@
|
||||
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
date coordinates in=x,
|
||||
width=\textwidth,
|
||||
height=0.375\textwidth,
|
||||
area style,
|
||||
ylabel={Total balance in €},
|
||||
y label style={at={(-0.1,0.5)},anchor=south},
|
||||
xticklabel=\month.\shortyear{\year},
|
||||
xtick=data,
|
||||
xticklabel style={
|
||||
rotate=60,
|
||||
anchor=near xticklabel,
|
||||
},
|
||||
grid,
|
||||
]
|
||||
\addplot+[mark=none, color=scol1, line width=1pt]
|
||||
table[col sep=comma, x=t, y=value]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user