【问题标题】:Changing font size of legend title in Python pylab rose/polar plot在 Python pylab 玫瑰/极坐标图中更改图例标题的字体大小
【发布时间】:2012-06-12 09:56:00
【问题描述】:

我正在尝试更改玫瑰图或“极地”图上现有图例标题的字体大小。大部分代码是由不在场的其他人编写的。我添加了:-

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)

感谢您的帮助

【问题讨论】:

  • 对于任何感兴趣的人,我们将其更改为使其工作:l= ax.legend(title=legend_title) setp(l.get_texts(), fontsize=12) setp(l.get_title (), 字体大小=12)

标签: python title font-size legend matplotlib


【解决方案1】:

这里有一个类似的问题: 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)

我的猜测是,有可能将替换 set_fontsize('#') 的任何标题属性更改为此处列出的其他参数:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      pyplot api 接受 title_fontsize 参数,用于 pyplot.legend()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多