1

Is there a way to update fontproperties of the axes without:

  • using rcParams or rc_context
  • using the specific axis
  • using set_xlabel/set_ylabel

I want to be able to update the labelsizes of the axes directly similar to the set function. Current methods I use have annoying syntax:

import matplotlib.pyplot as plt
props = dict(ylabel = 'ytest', xlabel = 'xtest')
# using rc_context
with plt.rc_context({'axes.labelsize' : 50}):
    fig, ax = plt.subplots()
    ax.set(**props)

fig, ax = plt.subplots()
ax.set(**props)
ax.yaxis.label.set_size(50)
ax.xaxis.label.set_size(50)

fig, ax = plt.subplots()
ax.set_ylabel('ytest', fontsize = 50)
ax.set_xlabel('xtest', fontsize = 50)

Preferably, I would like to access the font properties directly but the matplotlib api seems to have no option for this, am I missing something?

cvanelteren
  • 1,633
  • 9
  • 16
  • 1
    You can use `plt.rcParams["axes.labelsize"] = 50` if you don't want to use a context. You can also use `plt.setp([ax.yaxis.label, ax.xaxis.label], size=50)` if you want to use a single code line instead of two. Apart, I'm not sure what is undesireable about the options you preclude here. – ImportanceOfBeingErnest Feb 07 '19 at 12:07
  • I am currently looking at circa 1400 lines of code of plots that are produced with similar context values, but dissimilar labelsizes. Preferably I want to use one property dict which I can use and edit dynamically over different figures instead of setting a global variable when I change some particular property (which is what I am currently doing and requires 'too much bookkeeping than what I want it to be'). The closest to what I want is the `with' method above, was hoping the api had a hidden featuret that allows for a clean dict approach. Setp is also nice, another alt. would be a wrapper. – cvanelteren Feb 07 '19 at 12:13
  • So if all this code is inside of functions, you can decorate it with some `@labelsize(50)` decorator. Something like [this](https://stackoverflow.com/questions/9213600/function-acting-as-both-decorator-and-context-manager-in-python) may be of interest. – ImportanceOfBeingErnest Feb 07 '19 at 12:24
  • Yeah that's a great idea. I am also thinking of just subclassing the axes class and adding this feature. Was hoping of a more OOB solution. Thanks for your help, – cvanelteren Feb 07 '19 at 12:39

0 Answers0