Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to change the font size of the title of an existing legend on a rose, or 'polar', plot. Most of the code was written by somebody else, who is away. I've added:-

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

to add the title 'legend_title', which is a variable that the user enters a string for in a a different function that uses this code. The second line of this doesn't return an error but doesn't appear to do anything either. The complete code is below. 'Rose' and 'RoseAxes' are modules/functions written by somebody. Does anyone know of a way to change the legend title font size? I've found some examples for normal plots but can't find any for rose/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

like image 929
LaurieW Avatar asked Jun 08 '12 10:06

LaurieW


1 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()
like image 152
Hagne Avatar answered Oct 03 '22 10:10

Hagne