[英]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.