2011-08-16 87 views

回答

3

这涵盖了每个可能的文本对象并为每个文本对象设置字体大小。 (请注意,此例程已从原始发布更新)。它使用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?