From f9473e2f2ac483a103798e3eb846f5b080ae9bba Mon Sep 17 00:00:00 2001 From: freeram Date: Sat, 16 Mar 2024 18:20:38 -0600 Subject: [PATCH] Use barcharts instead --- pomodorodiscord/src/graphs.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/pomodorodiscord/src/graphs.py b/pomodorodiscord/src/graphs.py index 20ccca3..a5546d7 100644 --- a/pomodorodiscord/src/graphs.py +++ b/pomodorodiscord/src/graphs.py @@ -1,36 +1,57 @@ +import os +import sys import matplotlib.pyplot as plt -from utils import load_data +from matplotlib.ticker import MaxNLocator + +# Making sure you can run `python3 src/graphs.py` +current_dir = os.path.dirname(os.path.abspath(__file__)) +parent_dir = os.path.dirname(current_dir) +sys.path.append(parent_dir) + +from src.utils import load_data def graph_pomodoro_sessions(data): dates = list(data.get('sessions_by_date', {}).keys()) sessions = list(data.get('sessions_by_date', {}).values()) - print(sessions) - plt.figure(figsize=(10, 6)) - plt.plot(dates, sessions, marker='o') + plt.figure(figsize=(12, 8)) + plt.bar(dates, sessions, color='blue', alpha=0.5, width=1) + plt.title('Pomodoro Sessions per Day') plt.xlabel('Days') plt.ylabel('Pomodoro Sessions') + + # Format x-axis to display dates properly + ax = plt.gca() + ax.xaxis.set_major_locator(MaxNLocator(20)) plt.xticks(rotation=45) - plt.yticks(sessions) + plt.tight_layout() plt.show() + def graph_hours_studied(data): dates = list(data.get('seconds_by_date', {}).keys()) seconds = list(data.get('seconds_by_date', {}).values()) hours = [s / 3600 for s in seconds] - plt.figure(figsize=(10, 6)) - plt.plot(dates, hours, marker='o', color='red') + plt.figure(figsize=(12, 8)) + plt.bar(dates, hours, color='blue', alpha=0.5, width=1) + plt.title('Hours Studied per Day') plt.xlabel('Days') plt.ylabel('Hours Studied') + + # Format x-axis to display dates properly + ax = plt.gca() + ax.xaxis.set_major_locator(MaxNLocator(20)) plt.xticks(rotation=45) + plt.tight_layout() plt.show() + if __name__ == '__main__': data = load_data() graph_pomodoro_sessions(data)