5

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!

mneuner
  • 433
  • 5
  • 25

1 Answers1

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')

enter image description here

Community
  • 1
  • 1
Ianhi
  • 2,864
  • 1
  • 25
  • 24
  • 1
    I 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