def plot_weight():
weight = session.query(models.Weight).order_by(desc(models.Weight.date)).\
filter().all()
if not weight:
print("No data to plot.")
return
dates_x = [elem.date for elem in weight]
weight_y = [elem.value for elem in weight]
fig = plt.figure(figsize=(40, 5), dpi = 400, edgecolor='k')
ax = fig.add_subplot(111)
ax.set_xticks(dates_x)
ax.xaxis.grid(True)
ax.yaxis.grid(True)
xfmt = md.DateFormatter('%d-%m-%Y')
ax.xaxis.set_major_formatter(xfmt)
plt.suptitle("Weight evolution", fontsize=20)
plt.xlabel('Time', fontsize=18)
plt.ylabel('Weight (kg)', fontsize=16)
plt.subplots_adjust(bottom=0.2)
plt.xticks(rotation=90)
plt.plot(dates_x, weight_y, "o-")
plt.savefig('weight.png', dpi=400, bbox_inches='tight')
#plt.show()
plt.clf()
plt.cla() # clear axis
del fig
评论列表
文章目录