Use symlog scale instead of log

This commit is contained in:
Benjamin Loison 2024-10-02 00:33:11 +02:00
parent ef3e8ef337
commit f090374caf
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -39,6 +39,8 @@ PRINT_TRANSACTIONS = False
totalMonthlyDebits = [] totalMonthlyDebits = []
totalMonthlyCredits = [] totalMonthlyCredits = []
totalMonthlyDifferences = []
totals = []
firstDatetime = None firstDatetime = None
lastDatetime = None lastDatetime = None
for folder in sorted(os.listdir()): for folder in sorted(os.listdir()):
@ -66,6 +68,7 @@ for folder in sorted(os.listdir()):
currentAmount = initialAmount currentAmount = initialAmount
print('Initial amount', initialAmount) print('Initial amount', initialAmount)
print() print()
totals += [initialAmount]
started = True started = True
continue continue
else: else:
@ -82,6 +85,9 @@ for folder in sorted(os.listdir()):
print(f'Total monthly credit: {totalMonthlyCredit}') print(f'Total monthly credit: {totalMonthlyCredit}')
totalMonthlyDebits += [totalMonthlyDebit] totalMonthlyDebits += [totalMonthlyDebit]
totalMonthlyCredits += [totalMonthlyCredit] totalMonthlyCredits += [totalMonthlyCredit]
totalMonthlyDifference = totalMonthlyCredit - totalMonthlyDebit
#print(totalMonthlyDifference)
totalMonthlyDifferences += [totalMonthlyDifference]
break break
if firstLineOfPaymentRegex.match(line) is not None: if firstLineOfPaymentRegex.match(line) is not None:
if date is not None and PRINT_TRANSACTIONS: if date is not None and PRINT_TRANSACTIONS:
@ -108,21 +114,23 @@ def getMonthIndex(aDatetimeStr):
aDatetime = datetime.strptime(aDatetimeStr, '%Y%m%d.pdf') aDatetime = datetime.strptime(aDatetimeStr, '%Y%m%d.pdf')
return aDatetime.year * 12 + aDatetime.month 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) xTicks = range(getMonthIndex(firstDatetime), getMonthIndex(lastDatetime) + 1)
#print(len(xTicks)) # sign does not seem respected for `totalMonthlyDifferences`.
#print(len(totalMonthlyDebits)) #print(totalMonthlyDifferences)
plt.bar(xTicks, totalMonthlyDebits, alpha = ALPHA, label = 'Debit') #print(f'{min(totalMonthlyDifferences)}')
plt.bar(xTicks, totalMonthlyCredits, alpha = ALPHA, label = 'Credit') #print(f'{max(totalMonthlyDifferences)}')
totalMonthlyAmountAndLabel = (
#(totalMonthlyDebits, 'Debit'),
#(totalMonthlyCredits, 'Credit'),
(totalMonthlyDifferences, 'Difference'),
(totals, 'Total'),
)
for totalMonthlyAmount, totalMonthlyLabel in totalMonthlyAmountAndLabel:
plt.bar(xTicks, totalMonthlyAmount, alpha = ALPHA, label = totalMonthlyLabel)
plt.legend() plt.legend()
plt.yscale('log') # Hides negative
#plt.yscale('symlog')
ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,}')) ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,}'))
def getMonthName(monthIndex): def getMonthName(monthIndex):