Add logarithmic scale

This commit is contained in:
Benjamin Loison 2024-10-01 20:57:36 +02:00
parent b75d5fc86f
commit ef3e8ef337
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -7,6 +7,7 @@ import subprocess
import re import re
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.ticker as ticker import matplotlib.ticker as ticker
from datetime import datetime
path = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements/' path = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements/'
@ -38,12 +39,16 @@ PRINT_TRANSACTIONS = False
totalMonthlyDebits = [] totalMonthlyDebits = []
totalMonthlyCredits = [] totalMonthlyCredits = []
firstDatetime = None
lastDatetime = None
for folder in sorted(os.listdir()): for folder in sorted(os.listdir()):
for file in sorted(os.listdir(folder)): for file in sorted(os.listdir(folder)):
#folder = '2022' #folder = '2022'
#file = '20220321.pdf' #file = '20220321.pdf'
filePath = f'{folder}/{file}' filePath = f'{folder}/{file}'
print(filePath) print(filePath)
if firstDatetime is None:
firstDatetime = file
content = getTextFromPdf(filePath) content = getTextFromPdf(filePath)
lines = content.splitlines() lines = content.splitlines()
started = False started = False
@ -91,17 +96,42 @@ for folder in sorted(os.listdir()):
comment += [line] comment += [line]
#break #break
#break #break
lastDatetime = file
fig, ax = plt.subplots() fig, ax = plt.subplots()
plt.title('Monthly debits and credits') plt.title('Monthly debits and credits')
plt.xlabel('Date') plt.xlabel('Date')
plt.ylabel('') plt.ylabel('')
ALPHA = 0.5 ALPHA = 0.5
xTicks = range(len(totalMonthlyDebits))
def getMonthIndex(aDatetimeStr):
aDatetime = datetime.strptime(aDatetimeStr, '%Y%m%d.pdf')
return aDatetime.year * 12 + aDatetime.month
'''
print(firstDatetime)
print(lastDatetime)
exit(1)
'''
#print(getMonthIndex(firstDatetime))
#print(getMonthIndex(lastDatetime))
xTicks = range(getMonthIndex(firstDatetime), getMonthIndex(lastDatetime) + 1)
#print(len(xTicks))
#print(len(totalMonthlyDebits))
plt.bar(xTicks, totalMonthlyDebits, alpha = ALPHA, label = 'Debit') plt.bar(xTicks, totalMonthlyDebits, alpha = ALPHA, label = 'Debit')
plt.bar(xTicks, totalMonthlyCredits, alpha = ALPHA, label = 'Credit') plt.bar(xTicks, totalMonthlyCredits, alpha = ALPHA, label = 'Credit')
plt.legend() plt.legend()
plt.yscale('log')
ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,}')) ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,}'))
def getMonthName(monthIndex):
return datetime((monthIndex - 1) // 12, 1 + (monthIndex - 1) % 12, 1).strftime('%b %Y')
ticksLabels = [getMonthName(monthIndex) for monthIndex in xTicks]
plt.xticks(xTicks, ticksLabels, rotation = 90)
#plt.tight_layout()
# How to show the horizontal lines for subticks?
plt.grid(axis = 'y')
plt.show() plt.show()