简体   繁体   English

matplotlib直方图图例字体系列更改

[英]matplotlib Histogram legend font family change

Very quick question. 很快的问题。 I would like to change the font family of a legend within the following: 我想在以下内容中更改图例的字体系列:

ax.legend(loc='upper left', fontsize='xx-small', fontfamily=???)

However, I know that fontfamily is the wrong keyword argument. 但是,我知道fontfamily是错误的关键字参数。 My question is, what is the right kwarg to do this? 我的问题是,做这个的正确的kwarg是什么?

I'm not sure what the right argument is, or if this is even possible without changing default rc parameters... 我不确定正确的参数是什么,或者如果不改变默认的rc参数甚至可以做到这一点......

I have looked on stack overflow and on a host of other sites and help guides, but nothing specific to this. 我已经查看了堆栈溢出以及许多其他站点和帮助指南,但没有具体到此。

Legend has a keyword called prop (which is really for font properties ... why it's not fontprop or something like that I don't know) that you can use to specify font properties with a dictionary. Legend有一个名为prop的关键字(实际上是字体属性...为什么它不是fontprop或类似我不知道的东西),你可以使用它来用字典指定字体属性。 Your line of code would look something like this if you wanted, say, the serif family: 如果您想要serif系列,那么您的代码行看起来就像这样:

ax.legend(loc='upper left', prop={'family':'serif', 'size':'xx-small'})

Notice you have to move the size specification into the dictionary with the rest, prop will override fontsize . 请注意,您必须将大小规范移动到字典中,其余的prop将覆盖fontsize

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM