使用matplotlib生成多个图

问题描述

我正在尝试在matplot.lib文件中生成2个docx图。我生成的第一个图非常完美。但是,我生成的第二个图叠加到了第一张图上(我不知道为什么)

我的第一张图读取一个csv文件并生成绘图值,而我的第二张图仅使用硬编码值。

import matplotlib.pyplot as plt
import numpy as np

        #making a plot from a csv file that was uploaded to DB table
    if FileUpload.objects.filter(attribution_file_upload='pftest4.csv').exists():
        life3 = pd.read_csv(FileUpload.objects.get(attribution_file_upload='pftest4.csv').attribution_file_upload)
        life3.plot(kind='bar',x='status',y='item')
        plt.title('my plot title')
        plt.xlabel('years')
        plt.ylabel('Age')
        memfile = io.BytesIO()
        plt.savefig(memfile)
        doc.add_picture(memfile,width=Inches(4))
        memfile.close()

    #making a plot out of numbers that are already stored in saf defect table DB table
    y1 = 3
    y2 = 5
    korea_scores = (y1,y2)
    col_count = 2
    bar_width = .2
    index = np.arange(col_count)
    plt.bar(index,korea_scores,bar_width,alpha=.4,label="Korea")
    memfile2 = io.BytesIO()
    plt.savefig(memfile2)
    doc.add_picture(memfile2,width=Inches(4))
    memfile2.close()

在所附图片中,您将看到我的第二张图表发生了什么变化。我的第二张图应该只有2个值。但是相反,这两个值是与我所有的第一个绘图值一起生成的。有什么想法吗?

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...