2017-03-18 86 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