简体   繁体   English

存储绘制的数据供以后使用

[英]Store plotted data for later use

I do much (practically all) of my data analysis in Jupyter/iPython-notebooks. 我在Jupyter / iPython笔记本中做了很多(几乎所有)数据分析。 For convenience, I obviously also plot my data in those notebooks using matplotlib / pyplot . 为了方便起见,我显然也使用matplotlib / pyplot在这些笔记本中绘制了数据。 Some of those plots I need to recreate externally later on, for example to use them in latex . 我以后需要在外部重新创建其中一些图,例如在latex使用它们。 For this I save the corresponding data as textfiles to the harddrive. 为此,我将相应的数据作为文本文件保存到硬盘。 Right now, I manually create a numpy-array by stacking all the data needed for the plot, and save this using numpy.savetxt . 现在,我通过堆叠绘图所需的所有数据来手动创建一个numpy-array,并使用numpy.savetxt保存它。

What I would like to have is a way to save all data needed for a specific plot written to the same file in an (semi)automatic way, but I am at a loss if it comes to the smart way of doing so. 我想要的是一种以(半)自动的方式将写入特定文件的特定图所需的所有数据保存的方法,但是如果涉及到这样做的智能方法,我将一头雾水。

Thus I have two questions: 因此,我有两个问题:

  • Is it possible (and save to do) to create something like a plot-memory object, that stores all data plotted per figure, and has a method similar to Memoryobject.save_plot_to_file(figname) ? 是否有可能(并保存这样做)来创建类似绘图内存的对象,该对象存储每个图形绘制的所有数据,并具有类似于Memoryobject.save_plot_to_file(figname) This object would need to know which figure I am working on, so I would need to create a layer above matplotlib, or get this information from the matplotlib objects 该对象将需要知道我正在处理哪个图形,因此我需要在matplotlib上方创建一个层,或者从matplotlib对象获取此信息。

  • Is there a simpler way? 有没有更简单的方法? The python universe is huge, and I do not know half of it. python宇宙很大,我不知道它的一半。 Maybe something like this already exists? 也许这样的东西已经存在?

Edit : Clarification: I do not want to save the figure object. 编辑 :澄清:我希望保存的数字对象。 What I want to do is something like this: 我想做的是这样的:

fig = plt.figure()
fig.plot(x1, y1)
fig.plot(x2, y2 + y3)

# and at a later point
arrays = get_data_from_plot(fig)
data = process(arrays)
np.savetxt('textfile', data)

You could pickle the object (using the cPickle module). 您可以腌制对象(使用cPickle模块)。 See this question here . 在这里看到这个问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM