在绘图中不起作用:sharex = True,sharey = True

时间:2019-01-10 10:58:42

标签: python-3.x matplotlib

sharex=Truesharey=True在以下代码中不起作用:

   fig, ax = plot.subplots(sharex=True, sharey=True,figsize=(5, 5))
   for i in range(1,16):

         plot.subplot(4,4,i)

         im=plot.contourf(xlon[:],xlat[:],diffrain[i,:,:])

    fig.subplots_adjust(right=0.825)
    cax = fig.add_axes([0.85, 0.06, 0.035, 0.91])
   fig.colorbar(im, cax=cax)
 plot.show()

1 个答案:

答案 0 :(得分:1)

您将要决定是通过subplot还是subplots来创建轴-机器人不能同时通过两者来创建轴。对于这种简单的情况,subplots应该可以正常工作。

fig, axes = plot.subplots(4,4, sharex=True, sharey=True,figsize=(5, 5))
for i, ax in enumerate(axes.flat):
     im=ax.contourf(xlon[:],xlat[:],diffrain[i,:,:])

fig.subplots_adjust(right=0.825)
cax = fig.add_axes([0.85, 0.06, 0.035, 0.91])
fig.colorbar(im, cax=cax)
plot.show()