2017-03-18 43 views
1

我一直在使用不完整的matplot庫庫進行調整,ggplot不允許我。python ggplot legend size

p = ggplot(aes(x='meh',y='mah'),data=df) 
t = theme_gray() 
t._rcParams['font.size'] = 30 
t._rcParams['xtick.labelsize'] = 20 
t._rcParams['ytick.labelsize'] = 20 

p = p + t 

這個按預期工作。我現在希望增加的傳說,這我通過添加color參數創建的尺寸:

p = ggplot(aes(x='meh',y'mah',color='week'),data=df) 

here,我可以看到下面的參數編輯傳說:

t._rcParams['legend.fontsize'] = 20 

儘管沒有錯誤,這不會對圖例文字大小做任何事情。

+0

'y mah'在代碼可靠地返回一個錯誤。有幾種方法可以更改圖例字體大小,這裏給出了一個:http://stackoverflow.com/questions/20407773/increase-legend-font-size-ggplot2 – tagoma

+1

不幸的是'r'。 – LearningSlowly

+1

對不起,我沒有注意語言。 – tagoma

回答

2

經過多次測試,看起來圖例字體大小實際上由參數font.size控制。它看起來像xaxis和yaxis圖例字體大小不能獨立控制。

(在下面的圖像,即是color參數的圖例只是爲了說明的目的)

from ggplot import * 
p = ggplot(aes(x='date', y='beef', color='beef'), data=meat) + geom_line() 
t = theme_gray() 
t._rcParams['font.size'] = 40 # Legend font size 
t._rcParams['xtick.labelsize'] = 20 # xaxis tick label size 
t._rcParams['ytick.labelsize'] = 30 # yaxis tick label size 
t._rcParams['axes.labelsize'] = 30 # axis label size 
p + t 

enter image description here

+0

謝謝!你使用的是什麼版本的ggplot和matplotlib?我無法重新創建它:/ – LearningSlowly

+0

matplotlib:2.0.0b3和ggplot:0.6.8。你有沒有收到錯誤信息? – tagoma

+1

升級matplotlib取得了訣竅 - 非常感謝! – LearningSlowly