Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python matplotlib: how to automatically save figures in .fig format?

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.

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

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

like image 260
lily Avatar asked Apr 15 '14 15:04

lily


1 Answers

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,open('sinus.pickle','wb'))

And then load it from disk and display:

fig_object = pickle.load(open('sinus.pickle','rb'))
fig_object.show()
like image 102
sefira32 Avatar answered Sep 27 '22 23:09

sefira32