From e943f45625a60e96ca3bf8c7f617877dc49f9c58 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Fri, 10 Mar 2023 10:33:29 +1100 Subject: [PATCH] Show time on yaxis and start y-axis from 0 --- app.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 042711b..31b5ed7 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from flask import Flask, make_response, render_template, request, jsonify import jinja_partials from flask_htmx import HTMX import matplotlib.pyplot as plt +import matplotlib.dates as mdates import os @@ -157,17 +158,26 @@ def workout(user_id, workout_id): y_values = [reading.rpm for reading in cadence_readings] fig, ax = plt.subplots() ax.plot(x_values, y_values) - # ax.set_xlabel('Time') + ax.set_xlabel('Time') ax.set_ylabel('Cadence (RPM)') # ax.set_title( # 'Cadence Readings for Workout {}'.format(workout_id)) # Hide X and Y axes label marks - ax.xaxis.set_tick_params(labelbottom=False) + # ax.xaxis.set_tick_params(labelbottom=False) # ax.yaxis.set_tick_params(labelleft=False) # Hide X and Y axes tick marks - ax.set_xticks([]) + # ax.set_xticks([]) # ax.set_yticks([]) + # use formatters to specify major and minor ticks + # format date as hh:mm + ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M")) + # ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m")) + # ax.xaxis.set_minor_formatter(mdates.DateFormatter("%Y-%m")) + + # set the y-axis limits to start at 0 + ax.set_ylim(bottom=0) + # Save the graph to a bytes buffer buffer = io.BytesIO() plt.savefig(buffer, format='png',