簡體   English   中英

在Python pylab rose / polar plot中更改圖例標題的字體大小

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

我正在嘗試更改玫瑰或“極地”情節中現有圖例的標題字體大小。 大部分代碼都是由其他人寫的,他們不在。 我已經添加:-

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)

謝謝你的幫助

快速調整圖例和圖例標題中的字體大小:

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

這里有一個類似的問題: 如何設置Matplotlib軸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('#')的任何title屬性更改為此處列出的其他參數:

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

pyplot api接受pyplot.legend()title_fontsize參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM