使 matplotlib 图识别对 rc 参数的更改
Make matplotlib figure recognize changes to rc parameters
使用 plt.rc(...)
更改 matplotlib 的选项后,我无法 "update" 图形。
(我在 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()
标签大小不会更新。
根据 this documenation,我假设 fig.canvas.draw()
会成功。
背景:我有几个腌制的图形对象,我需要在加载后进行调整。
大多数 rcParameters 在创建各自的对象时生效。在创建轴后更改轴属性无效。
您当然可以创建新图形和坐标轴。或者,您可以通过 API 更改现有艺术家的属性。例如。
fig.get_axes()[0].title.set_fontsize(20)
在这种情况下。
使用 plt.rc(...)
更改 matplotlib 的选项后,我无法 "update" 图形。
(我在 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()
标签大小不会更新。
根据 this documenation,我假设 fig.canvas.draw()
会成功。
背景:我有几个腌制的图形对象,我需要在加载后进行调整。
大多数 rcParameters 在创建各自的对象时生效。在创建轴后更改轴属性无效。
您当然可以创建新图形和坐标轴。或者,您可以通过 API 更改现有艺术家的属性。例如。
fig.get_axes()[0].title.set_fontsize(20)
在这种情况下。