Skip to content Skip to sidebar Skip to footer

In Matplotlib, How Do You Change The Fontsize Of A Single Figure?

The code: # changes the fontsize of matplotlib, not just a single figure matplotlib.rcParams.update({'font.size': 22}) Is there a better way than setting it for a figure, and then

Solution 1:

This covers every possible text object and sets the font size for each. (Note this routine has been updated from the original posting). It uses the findobj method of the Artist base class. The match keyword accepts a boolean function that performs a test on each object that is a child of the figure. I use this to test if the artist resides in the 'matplotlib.text' module. This is general enough to be used for any artist, not just a figure.

defset_fontsize(fig,fontsize):
    """
    For each text object of a figure fig, set the font size to fontsize
    """defmatch(artist):
        return artist.__module__ == "matplotlib.text"for textobj in fig.findobj(match=match):
        textobj.set_fontsize(fontsize)

This has been updated based on responses to this question: Is there anything wrong with importing a python module into a routine or class definition?

Post a Comment for "In Matplotlib, How Do You Change The Fontsize Of A Single Figure?"