Getting an object in Python Matplotlib -


to make plot, have written code in following fashion:

from pylab import *  x = [1,2,3] y = [1,2,3]  matplotlib.pyplot.scatter(x,y,label='blah') matplotlib.pyplot.legend(title='title') matplotlib.pyplot.show() 

i want change font size of legend title. way go legend object , change title way (e.g., how set font size of matplotlib axis legend?)

instead of rewriting code using ax.xxx, figure.xxx, etc, there way @ legend object code have written, , go there?

that say, how define

legend 

from original piece of code, such that

title = legend.get_title() title.set_fontsize(30) 

would @ title object , allow me play .get_title()?

i think i'm on verge of eureka moment regarding object-orientated languages. have feeling answer give me eureka moment!

cheers,

ged

first, in code should stick using either from pylab import * , use imported methods directly, or import matplotlib.pyplot plt , plt.* instead of matplotlib.pyplot.*. both these "conventions" when comes working matplotlib. latter (i.e. pyplot) preferred scripting, pylab used interactive plotting.

to better understand difference between pylab , pyplot see matplotlib faq.

over problem @ hand; "get" object in python, assign object variable.

from pylab import *  x = [1,2,3] y = [1,2,3]  scatter(x,y,label='blah')  # assign legend object variable leg leg = legend(title='title') leg_title = leg.get_title() leg_title.set_fontsize(30)  # optionally can use one-liner #legend(title='title').get_title().set_fontsize(30)  show() 

visual comparison (rightmost subplot produced above code):

visual comparison , without specified fontsize


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -