2

编码:

# changes the fontsize of matplotlib, not just a single figure
matplotlib.rcParams.update({'font.size': 22})

有没有比将其设置为一个数字,然后再将其设置回来更好的方法?

4

1 回答 1

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)

这已根据对以下问题的回答进行了更新:将 python 模块导入例程或类定义有什么问题吗?

于 2011-08-16T18:33:49.703 回答