Show time on yaxis and start y-axis from 0

This commit is contained in:
Peter Stockings
2023-03-10 10:33:29 +11:00
parent 36438b125c
commit e943f45625

16
app.py
View File

@@ -5,6 +5,7 @@ from flask import Flask, make_response, render_template, request, jsonify
import jinja_partials import jinja_partials
from flask_htmx import HTMX from flask_htmx import HTMX
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import os import os
@@ -157,17 +158,26 @@ def workout(user_id, workout_id):
y_values = [reading.rpm for reading in cadence_readings] y_values = [reading.rpm for reading in cadence_readings]
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot(x_values, y_values) ax.plot(x_values, y_values)
# ax.set_xlabel('Time') ax.set_xlabel('Time')
ax.set_ylabel('Cadence (RPM)') ax.set_ylabel('Cadence (RPM)')
# ax.set_title( # ax.set_title(
# 'Cadence Readings for Workout {}'.format(workout_id)) # 'Cadence Readings for Workout {}'.format(workout_id))
# Hide X and Y axes label marks # 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) # ax.yaxis.set_tick_params(labelleft=False)
# Hide X and Y axes tick marks # Hide X and Y axes tick marks
ax.set_xticks([]) # ax.set_xticks([])
# ax.set_yticks([]) # 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 # Save the graph to a bytes buffer
buffer = io.BytesIO() buffer = io.BytesIO()
plt.savefig(buffer, format='png', plt.savefig(buffer, format='png',