简体   繁体   English

将多个图存储在列表中以便以后访问它们

[英]store several plots in a list to access them later

I create in my python file several plots with matplotlib.我在我的 python 文件中创建了几个带有 matplotlib 的图。 I want to access them later and plot them on a VTK object.我想稍后访问它们,然后在 VTK object 上访问它们。 I tried to create a list and just append them as plot objects.我试图创建一个列表,只是 append 它们作为 plot 对象。

for i in range(len(x)):
    ax = plt.subplot(111, projection='polar')
    plt.legend()
    plot_l.append(plt.show())

But this does not work quite well.但这并不能很好地工作。 I also tried with plt.savefig('somewhere/folder') and reload them out of the file.我还尝试使用plt.savefig('somewhere/folder')并将它们从文件中重新加载。

But this does not meet me needs, because I have a huge amount of plots I want to have the plots just in the file.但这并不能满足我的需求,因为我有大量的地块,我想把这些地块放在文件中。

How do I store several plots as png to access them later, like plot_l[10] ?如何将多个图存储为png以便以后访问它们,例如plot_l[10] Or is there a better alternative?还是有更好的选择?

Cheers,干杯,

You might want to try saving your ax object, instead.您可能想尝试保存您的ax object,而不是。

import pickle

# [...your plotting code here...]

pickle.dump(ax, file('filename', 'w'))

And this is how you would load it next time you need it:这就是您下次需要时加载它的方式:

ax = pickle.load(file('filename'))

In your specific case, you might prefer to put this inside a loop and have filename depend on the looping index, etc.在您的特定情况下,您可能更喜欢将其放在循环中,并且filename取决于循环索引等。

And finally, you might want to try the same with a list object, to keep everything in one file, as you indicated.最后,您可能想尝试使用列表 object 进行相同操作,以将所有内容保存在一个文件中,如您所指示的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将功能存储在列表中并稍后调用它们 - Store functions in list and call them later 绘制几个图中的图片列表 - Plotting list of picturelists in several plots Python-程序退出时重置列表,如何将对象存储在列表中以供以后访问? - Python - list reset on program exit, how to store objects in list to access later? 如何访问彼此嵌套的多个字典和列表层并将它们收集到列表中 - how to access several layers of dictionaries and lists nested within each other and collect them into a list 如何使用 Pandas 创建特定的图,然后将它们存储为 PNG 文件? - How to create specific plots using Pandas and then store them as PNG files? 在Django views.py中创建变量,并在以后访问它们 - Create variables in Django views.py and access them at later point 多次访问字典或存储在临时变量中 - Access dictionary several times or store in temporary variable 将临时数据存储在数组中还是将其保存到文件中以供以后访问是否更好? - Is it better to store temp data in arrays or save it to file for access later? 算法从列表中访问两个随机元素,将它们存储在变量中并从 Python 3.x 中的原始列表中删除元素? - Algorithim to access two random elements from a list, store them in a variable and delete the elements from the original list in Python 3.x? 是否可以将 .txt 的每一行存储为一个列表,然后再使用它? - Is it possible to store each line of a .txt into as a list and then use it later?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM