actual_panda
actual_panda

Reputation: 1260

Make matplotlib figure recognize changes to rc parameters

I am unable to "update" a figure after making changes to matplotlib's options with plt.rc(...).

(I am using Python 3.6.8 in interactive mode with IPython.)

Here's (a minimal example of) what I'm trying to do:

In [1]: %matplotlib tk                                                                
In [2]: import matplotlib.pyplot as plt                                               
In [3]: plt.rc('axes', labelsize=5)                                                   
In [4]: fig = plt.figure()                                                            
In [5]: plt.plot([1,2,3], [4,5,6])                                                    
Out[5]: [<matplotlib.lines.Line2D at 0x7ffb128accc0>]
In [6]: fig.get_axes()[0].set_xlabel('This is the x label')                           
Out[6]: Text(0.5, 23.52222222222222, 'This is the x label')
In [7]: plt.rc('axes', labelsize=20)                                                  
In [8]: fig.canvas.draw()

This produces a plot with a very small x-axis label. Unfortunately, after

plt.rc('axes', labelsize=20)
fig.canvas.draw()

the label size does not update.

According to this documenation I assumed fig.canvas.draw() would do the trick.

Background: I have a couple of pickled figure objects which I need to adjust after loading.

Upvotes: 0

Views: 570

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339280

Most rcParameters take effect when the respective object is created. Changing axes properties after the axes is created has no effect.

You could create a new figure and axes of course. Or, you can change the attributes of the existing artists via their API. E.g.

fig.get_axes()[0].title.set_fontsize(20) 

in this case.

Upvotes: 1

Related Questions