只有最后一个子图有较小的网格线

Only the last subplot has minor gridlines

我想用数据框列绘制一个子图,所以我执行以下代码:

fig, axes = plt.subplots(1, 2, figsize=(10,10), tight_layout=True)

plt.minorticks_on()
plt.grid(which='minor', linestyle='-', alpha=0.5)

ori_df.plot(x='Predicted', y='Actual', kind='scatter', ax=axes[0])
ori_df.plot(x='Predicted', y='# Difference', kind='scatter', ax=axes[1])

plt.show()

但是,为什么只有最后一张图有小网格线?

您需要指定每个轴:

axes[0].grid(which='minor', linestyle='-', alpha=0.5)
axes[1].grid(which='minor', linestyle='-', alpha=0.5)

或:

for axis in axes:
    axis.grid(which='minor', linestyle='-', alpha=0.5)

minorticks_on()

也一样