2
代码:在matplotlib中,如何更改单个数字的字体大小?
# changes the fontsize of matplotlib, not just a single figure
matplotlib.rcParams.update({'font.size': 22})
难道还有比设定它的图形,然后将它设置回来以后更好的办法?
代码:在matplotlib中,如何更改单个数字的字体大小?
# changes the fontsize of matplotlib, not just a single figure
matplotlib.rcParams.update({'font.size': 22})
难道还有比设定它的图形,然后将它设置回来以后更好的办法?
这涵盖了每个可能的文本对象并为每个文本对象设置字体大小。 (请注意,此例程已从原始发布更新)。它使用Artist基类的findobj方法。 match关键字接受一个布尔函数,该函数对图形中的每个对象执行测试。我使用它来测试艺术家是否驻留在“matplotlib.text”模块中。这一般足以用于任何艺术家,而不仅仅是一个人物。
def set_fontsize(fig,fontsize):
"""
For each text object of a figure fig, set the font size to fontsize
"""
def match(artist):
return artist.__module__ == "matplotlib.text"
for textobj in fig.findobj(match=match):
textobj.set_fontsize(fontsize)
这已更新基于这个问题的回答:Is there anything wrong with importing a python module into a routine or class definition?