is there a conventient way to update an already existing matplotlib figure with new rcParams? Background is that i want to export figures with different properties (e.g. line-width, fonts ..). Is there something like a 'redraw()' option? Thank you!
Asked
Active
Viewed 1,479 times
5
-
Could you not set the rcParams before each plot? – DavidG Jul 22 '16 at 07:57
-
No, because the onscreen figures should not necessarily look like the exported ones. – mneuner Jul 22 '16 at 08:11
1 Answers
1
use fig.canvas.draw()
See How to update a plot in matplotlib? or how do I redraw an image using python's matplotlib?
In a jupyter notebook:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['figure.figsize']=(5,5)
mpl.rcParams['font.size']=50
fig = plt.figure()
x = [1,2,3]
y = [3,4,5]
plt.plot(x,y,label='data')
plt.legend()
plt.show()
mpl.rcParams['font.size']=5
fig.canvas.draw()
fig.savefig('saved.png')
from IPython.display import Image
Image('saved.png')
-
1I have trouble recreating your code. The second plot has always the same fontsize as the first one. I'm using Python 3.9.10, matplotlib 3.5.3, jupyterlab 3.4.5. – eco Aug 29 '22 at 13:41