我想在绘制的图上添加更多细粒度的网格。问题是所有需要访问轴对象的例子。 我想添加特定的网格到已绘制的图形(从ipython内部)。ipython:获取当前图()
如何在ipython中访问当前图形和坐标轴?
我想在绘制的图上添加更多细粒度的网格。问题是所有需要访问轴对象的例子。 我想添加特定的网格到已绘制的图形(从ipython内部)。ipython:获取当前图()
如何在ipython中访问当前图形和坐标轴?
随着plt?
示例(假设ipython --pylab
)
In [44]: x=np.arange(0,5,.1)
In [45]: y=np.sin(x)
In [46]: plt.plot(x,y)
Out[46]: [<matplotlib.lines.Line2D at 0xb09418cc>]
figure 1
显示;得到它的手柄:
In [47]: f=plt.figure(1)
In [48]: f
Out[48]: <matplotlib.figure.Figure at 0xb17acb2c>
及其轴线的列表:
In [49]: f.axes
Out[49]: [<matplotlib.axes._subplots.AxesSubplot at 0xb091198c>]
打开网格上的电流(只)轴:
In [51]: a=f.axes[0]
In [52]: a.grid(True)
我没有在一段时间内使用了plt,所以通过制作情节和搜索标签完成来找到这些东西?为可能的东西。我很确定这也可以在plt
文档中找到。
或者你可以先创建人物,并挂在其手柄
In [53]: fig=plt.figure()
In [55]: ax1=fig.add_subplot(2,1,1)
In [56]: ax2=fig.add_subplot(2,1,2)
In [57]: plt.plot(x,y)
Out[57]: [<matplotlib.lines.Line2D at 0xb12ed5ec>]
In [58]: fig.axes
Out[58]:
[<matplotlib.axes._subplots.AxesSubplot at 0xb0917e2c>,
<matplotlib.axes._subplots.AxesSubplot at 0xb17a35cc>]
而且还有gcf
和gca
(获取当前图/轴)。和MATLAB一样,如果我的记忆是正确的。
In [68]: plt.gca()
Out[68]: <matplotlib.axes._subplots.AxesSubplot at 0xb17a35cc>
In [66]: plt.gcf()
Out[66]: <matplotlib.figure.Figure at 0xb091eeec>
(这些被用来在侧栏链接:Matplotlib.pyplot - Deactivate axes in figure. /Axis of figure overlap with axes of subplot)
plt.gcf()
来获取当前的数字
plt.gca()
来获取当前的轴线