これはすべての可能なテキストオブジェクトをカバーし、それぞれのフォントサイズを設定します。 (このルーチンは元の投稿から更新されています)。 Artistベースクラスのfindobjメソッドを使用します。 matchキーワードは、Figureの子である各オブジェクトに対してテストを実行するboolean関数を受け入れます。これは、アーティストが '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?