使matplotlib图识别对rc参数的更改

2024-04-18 16:22:45 发布

您现在位置:Python中文网/ 问答频道 /正文

使用plt.rc(...)更改matplotlib的选项后,我无法“更新”图形。你知道吗

(我在与IPython的交互模式下使用python3.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()会成功。你知道吗

背景:我有几个腌制的图形对象,需要在加载后进行调整。你知道吗


Tags: thein图形matplotlibisfigpltout
1条回答
网友
1楼 · 发布于 2024-04-18 16:22:45

大多数参数在创建相应对象时生效。在创建轴之后更改轴属性没有效果。你知道吗

当然,你可以创建一个新的图形和轴。或者,您可以通过现有艺术家的API更改其属性。例如

fig.get_axes()[0].title.set_fontsize(20) 

在这种情况下。你知道吗

相关问题 更多 >