2011-08-16 85 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?