首页 > 解决方案 > 如何将 matplotlib 图保存到列表中,然后显示它们?

问题描述

我正在运行 Python,并且正在像这样的 for 循环中创建一系列直方图:

hist_dict = {}

for data, name in zip([mon, tue, wed, thu, fri], 
['Monday','Tuesday','Wednesday','Thursday','Friday']):
    plt.figure()
    plt.title("Call Distribution for " + name)
    plt.xlabel("Number of Daily Calls")
    plt.ylabel("Number of Days")
    plt.xlim(0, 1200)
    hist_dict[name] = plt.hist(data, bins=24)

将图像保存到我的字典(或列表,我不知道是否重要)后,我可以调用它们并显示它们吗?我努力了

hist_dict["Monday"].show()
plt.show(hist_dict["Monday"])
hist_dict["Monday"]

似乎没有任何效果。如果这不起作用,那么在本地保存图(而不是 png 文件)以便我可以安排到子图设置中的最佳方法是什么?

标签: pythonpython-3.xmatplotlib

解决方案


推荐阅读