使用 .更改 matplotlib 的选项后,我无法“更新”图形plt.rc(...)
。
(我在与 IPython 的交互模式下使用 Python 3.6.8。)
这是我正在尝试做的(一个最小的例子):
In [1]: %matplotlib tk
In [2]: import matplotlib.pyplot as plt
In [3]: plt.rc('axes', labelsize=5)
In [4]: fig = plt.figure()
In [5]: plt.plot([1,2,3], [4,5,6])
Out[5]: [<matplotlib.lines.Line2D at 0x7ffb128accc0>]
In [6]: fig.get_axes()[0].set_xlabel('This is the x label')
Out[6]: Text(0.5, 23.52222222222222, 'This is the x label')
In [7]: plt.rc('axes', labelsize=20)
In [8]: fig.canvas.draw()
这会生成一个带有非常小的 x 轴标签的图。不幸的是,之后
plt.rc('axes', labelsize=20)
fig.canvas.draw()
标签大小不会更新。
根据这个文档,我认为fig.canvas.draw()
可以解决问题。
背景:我有几个腌制的图形对象,我需要在加载后进行调整。