How to change all text sizes in figure when using python matplotlib? -


i saw long time ago function changed text sizes same in matplotlib. can't find anywhere. simple 1 (or two) liner like:

for item in pylab.gca(): item.getlabel().setsize(10) 

how should above? above pseudocode, idea change x , y labels, legends, titles, everything.

edit: ...inside 1 figure (object). want text size dependent on figure width. global font.size changes figures? , think cannot applied dynamically (settings read before figure created)?

edit 2: tested font.size = 22 method. has weird behavior if run after e.g. legend(). text vertical spaces not updated. so, should gettext().settextsize().

instead of changing font size change figsize (the font size stays same):

# figsize = (8,6) figsize = (4,3) # same ratio, bigger text fig,(ax) = plt.subplots(1, 1, figsize=figsize) 

edit (for completeness): size of pixels (on screen) controlled dpi setting settable i.e. figure.set_dpi( val ).

edit 2: don't know how (and if) can control exact pixel height. did tests though:

#! /usr/bin/env python  import matplotlib import matplotlib.pyplot plt import numpy np  x = np.arange(0, 2*np.pi, 0.1) y = np.sin(x)  matplotlib.rcparams.update({'font.size': 10}) fig,(ax) = plt.subplots(1, 1, figsize=(10,10)) plt.plot(x,y) plt.savefig('test.png', dpi=300)  # font-size, figsize, dpi => pixel-height # 10, 20x20, 100 => 10 # 10, 20x20, 200 => 21 # 10, 10x10, 100 => 10 # 10, 10x10, 200 => 21 # 10, 10x10, 300 => 34 

also note there effects on pixel height due anti-aliasing.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -