存储并重新加载matplotlib.pyplot对象 [英] Store and reload matplotlib.pyplot object

查看:153
本文介绍了存储并重新加载matplotlib.pyplot对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在伪操作环境中工作,我们在收到数据后制作新图像.有时,当有新数据输入时,我们需要重新打开图像并更新该图像以创建合成,添加叠加等.除了添加到图像之外,还需要修改标题,图例等.

matplotlib中是否内置某些东西,可以让我存储和重新加载matplotlib.pyplot对象以备后用?它需要保持对所有相关对象(包括图形,线条,图例等)的访问.也许腌制是我想要的,但我对此表示怀疑.

解决方案

从1.2版开始,matplotlib附带了实验性酸洗支持.如果您遇到任何问题,请在mpl邮件列表上或在github.com/matplotlib/matplotlib

上打开问题,让我们知道.

HTH

编辑:添加了一个简单示例

import matplotlib.pyplot as plt
import numpy as np
import pickle

ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
pickle.dump(ax, file('myplot.pickle', 'w'))

然后在单独的会话中:

import matplotlib.pyplot as plt
import pickle

ax = pickle.load(file('myplot.pickle'))
plt.show()

I work in an psudo-operational environment where we make new imagery on receipt of data. Sometimes when new data comes in, we need to re-open an image and update that image in order to create composites, add overlays, etc. In addition to adding to the image, this requires modification of titles, legends, etc.

Is there something built into matplotlib that would let me store and reload my matplotlib.pyplot object for later use? It would need to maintain access to all associated objects including figures, lines, legends, etc. Maybe pickle is what I'm looking for, but I doubt it.

解决方案

As of 1.2 matplotlib ships with experimental pickling support. If you come across any issues with it, please let us know on the mpl mailing list or by opening an issue on github.com/matplotlib/matplotlib

HTH

EDIT: Added a simple example

import matplotlib.pyplot as plt
import numpy as np
import pickle

ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
pickle.dump(ax, file('myplot.pickle', 'w'))

Then in a separate session:

import matplotlib.pyplot as plt
import pickle

ax = pickle.load(file('myplot.pickle'))
plt.show()

这篇关于存储并重新加载matplotlib.pyplot对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆