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

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

问题描述

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

matplotlib 中是否有内置的东西可以让我存储和重新加载我的 matplotlib.pyplot 对象以供以后使用?它需要保持对所有相关对象的访问,包括图形、线条、图例等.也许 pickle 是我正在寻找的,但我对此表示怀疑.

解决方案

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

HTH

编辑:添加了一个简单的例子

将 matplotlib.pyplot 导入为 plt将 numpy 导入为 np进口泡菜ax = plt.subplot(111)x = np.linspace(0, 10)y = np.exp(x)plt.plot(x, y)pickle.dump(ax, file('myplot.pickle', 'w'))

然后在一个单独的会话中:

将 matplotlib.pyplot 导入为 plt进口泡菜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天全站免登陆