在Python的pylab极坐标图中更改图例标题的字体大小

8

我正在尝试更改极坐标图例中现有标题的字体大小。大部分代码是由其他人编写的,而这个人不在场。我已经添加了:

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

为了添加标题“legend_title”,用户在另一个使用此代码的函数中输入字符串作为变量。这段代码的第二行没有返回错误,但是似乎也没有做任何事情。完整的代码如下。“Rose”和“RoseAxes”是由某人编写的模块/函数。有人知道如何更改图例标题字体大小吗?我已经找到了一些普通绘图的示例,但是找不到任何用于玫瑰图/极坐标图的示例。

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)

感谢任何帮助


2
对于任何感兴趣的人,这是我们所做的更改以使其工作:l = ax.legend(title = legend_title) setp(l.get_texts(), fontsize = 12) setp(l.get_title(), fontsize = 12) - LaurieW
3个回答

11

快速调整图例和图例标题字体大小的方法:

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()

4
这里有一个类似的问题: 如何设置Matplotlib轴图例的字体大小? 我成功地使用第二个答案改变了标题的字体大小,我发现这是最简单的方法。您还可以更改标题的颜色和其他属性。我得到了以下代码:
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)

我猜测可以通过将`set_fontsize('#')`替换为其他参数来更改任何标题属性,这些参数在此列出:

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


4

pyplot api接受pyplot.legend()title_fontsize参数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接