python matplotlib:如何以.fig格式自动保存数字? [英] python matplotlib: how to automatically save figures in .fig format?

查看:124
本文介绍了python matplotlib:如何以.fig格式自动保存数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过python matplotlib模块,我们可以使用pylab.savefig()函数保存图形.然而,这个函数似乎不能用于以 .fig 格式保存数字..fig格式为matlab图形格式.

With python matplotlib module, we can use pylab.savefig() function to save figures. However it seems that this function can't be used to save figures in .fig format. The .fig format is matlab figure format.

使用.fig格式,我们可以调整/修改图形,这就是为什么要将图形保存为.fig格式的原因.

With .fig format, we can adjust/modify the figures, that is why I want to save figures into .fig format.

那么有没有什么方法可以用 python matplotlib 以 .fig 格式保存图形?

So are there any ways to save figures in .fig format with python matplotlib?

推荐答案

你可以像这样pickle一个图形到磁盘

You can pickle a figure to disk like this

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

# Plot
fig_object = plt.figure()
x = np.linspace(0,3*np.pi)
y = np.sin(x)
plt.plot(x,y)
# Save to disk
pickle.dump(fig_object,file('sinus.pickle','w'))

然后从磁盘加载并显示:

And then load it from disk and display:

fig_object = pickle.load(open('sinus.pickle','rb'))
fig_object.show()

这篇关于python matplotlib:如何以.fig格式自动保存数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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