在Python pylab rose/polar p中更改图例标题的字体大小

2024-05-19 11:31:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更改玫瑰图或“极轴”图上现有图例标题的字体大小。大部分代码都是别人写的,他不在家。我补充道:

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)

谢谢你的帮助


Tags: 代码fromimport标题gettitlefigxml
3条回答

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

这里有一个类似的问题: How to set font size of Matplotlib axis Legend?

我设法用第二个答案改变标题的字体大小,我发现这是最简单的答案。也可以更改颜色标题和其他属性。我得到了以下代码:

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)

我的猜测是,可以将任何title属性更改为以下列出的其他参数,以替换set掼fontsize('掼'):

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

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

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

相关问题 更多 >

    热门问题