plot.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:health 作者: cedricbonhomme 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号