Changing the font size of the legend header in Python pylab rose / polar plot

I am trying to change the font size of the name of an existing legend on a pink or "polar" plot. Most of the code was written by someone else who left. I added: -

ax.legend(title=legend_title) setp(l.get_title(), fontsize=8) 

to add the header "legend_title", which is a variable that the user enters into a string for another function that uses this code. The second line of this does not return an error, but it seems to do nothing either. The full code is given below. "Rose" and "RoseAxes" are modules / functions written by someone. Does anyone know how to change the font size of the legend name? I found some examples for ordinary plots, but I can not find them for roses / polar plots.

 from Rose.RoseAxes import RoseAxes from pylab import figure, title, setp, close, clf from PlotGeneration import color_map_xml fig = figure(1) rect = [0.02, 0.1, 0.8, 0.8] ax = RoseAxes(fig, rect, axisbg='w') fig.add_axes(ax) if cmap == None: (XMLcmap,colors) = color_map_xml.get_cmap('D:/HRW/VET/HrwPyLibs/ColorMapLibrary/paired.xml',255) else: XMLcmap = cmap bqs = kwargs.pop('CTfigname', None) ax.box(Dir, U, bins = rose_binX, units = unit, nsector = nsector, cmap = XMLcmap, lw = 0, **kwargs ) l = ax.legend() ax.legend(title=legend_title) setp(l.get_texts(), fontsize=8) setp(l.get_title(), fontsize=8) 

Thanks for any help

+8
source share
3 answers

quick way to adjust font sizes in legend and legend title:

 import numpy as np import pylab as plt f,ax = plt.subplots() x = np.arange(10) y = np.sin(x) ax.plot(x,y, label = 'sin') leg = ax.legend(fontsize = 'large') leg.set_title("title", prop = {'size':'x-large'}) f.show() 
+9
source

There is a similar question here: How to set the font size of the Matplotlib Legend axis?

I manage to change the font size of the title bar using the second answer, which I consider the simplest. You can also change the color name and other properties. I got the following code:

 leg=legend((x3, x4,),shadow=False, loc=loca,title=labelE,prop={'size':8}) leg.draw_frame(False) ax111.get_legend().get_title().set_fontsize('36') ax111.yaxis.set_tick_params(labelsize=10) 

I assume that you can change any title property that replaces set_fontsize ('#') with another parameter specified here:

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend

+4
source

pyplot api accepts the title_fontsize parameter for pyplot.legend() .

0
source

All Articles