此问题在此处已有答案:
What is the difference between drawing plots using plot, axes or figure in matplotlib?(2个答案)
9小时前关门了。
我使用matplotlib和下面的代码网格只有第二子图,而不是第一个。我不能找出问题。你认为问题是什么,如何网格两个数字?
谢谢
ep = np.linspace(1, 500, 500)
fig, axs = plt.subplots(2)
plt.grid()
axs[0].set_title('me')
axs[0].set(xlabel='you', ylabel='me')
axs[0].plot(ep, me_es)
axs[1].set(xlabel='ty', ylabel='no')
axs[1].set_title('sec')
axs[1].plot(ep,me_es)
plt.tight_layout(pad=1, w_pad=1.5, h_pad=2.0)
plt.rcParams['figure.figsize'] = (12.4, 10.8)
这是我得到的数字。
1条答案
按热度按时间1aaf6o9v1#
plt.grid()
等同于plt.gca().grid()
(见此处)。gca()
代表“获取当前轴”(see here)。因此,它将网格化最后创建的当前轴:这里是第二个,换句话说,在这里plt.grid()
=axs[1].grid()
添加
axs[0].grid()
应该对您起作用。