也许我们可以在上面叠加另一个图:
fig, axes = plt.subplots(1, 4, figsize=(9, 2), subplot_kw=dict(polar=True))
for aa in axes.flat:
aa.plot(theta, r, '-sb')
aa.set_rlim(0, 1)
aa.set_yticklabels([])
box=axes[0].get_position()
axl=fig.add_axes([box.xmin/2, #put it half way between the edge of the 1st subplot and the left edge of the figure
0.5*(box.ymin+box.ymax), #put the origin at the same height of the origin of the polar plots
box.width/40, #Doesn't really matter, we will set everything invisible, except the y axis
box.height*0.4], #fig.subplots_adjust will not adjust this axis, so we will need to manually set the height to 0.4 (half of 0.9-0.1)
axisbg=None) #transparent background.
axl.spines['top'].set_visible(False)
axl.spines['right'].set_visible(False)
axl.spines['bottom'].set_visible(False)
axl.yaxis.set_ticks_position('both')
axl.xaxis.set_ticks_position('none')
axl.set_xticklabels([])
axl.set_ylim(0,1)
axl.set_ylabel('$R$\t', rotation=0)
fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9, wspace=0.5)
编辑
原来subplots_adjust 也会影响叠加轴。如果我们检查fig 中的轴列表,叠加轴就在那里(如果您有疑问,请检查 site-packages\matplotlib\figure.py):
In [27]:
fig.axes
Out[27]:
[<matplotlib.axes.PolarAxesSubplot at 0x9714650>,
<matplotlib.axes.PolarAxesSubplot at 0x9152730>,
<matplotlib.axes.PolarAxesSubplot at 0x9195b90>,
<matplotlib.axes.PolarAxesSubplot at 0x91878b0>,
<matplotlib.axes.Axes at 0x9705a90>]
真正的问题是wspace=0.5 不仅会影响极坐标图的宽度,还会影响高度(因此纵横比保持不变)。但对于非极性叠加轴,它只影响宽度。因此,需要额外修改宽度,解决方法是:
fig, axes = plt.subplots(1, 4, figsize=(10, 2), subplot_kw=dict(polar=True))
for aa in axes.flat:
aa.plot(theta, r, '-sb')
aa.set_rlim(0, 1)
aa.set_yticklabels([])
#fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9, wspace=0.5)
box=axes[0].get_position()
axl=fig.add_axes([box.xmin/2,
0.5*(box.ymin+box.ymax),
box.width/40,
box.height*0.5],
axisbg=None)
#fig.add_axes([box.xmin, box.ymin, box.width, box.height])
axl.spines['top'].set_visible(False)
axl.spines['right'].set_visible(False)
axl.spines['bottom'].set_visible(False)
axl.yaxis.set_ticks_position('both')
axl.xaxis.set_ticks_position('none')
axl.set_xticklabels([])
axl.set_ylim(0,1)
axl.set_ylabel('$R$\t', rotation=0)
w_pre_scl=box.width
fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9, wspace=0.5)
ratio=axes[0].get_position().width/w_pre_scl
axlb=axl.get_position()
axl.set_position([axlb.xmin, axlb.ymin, axlb.width, axlb.height*ratio])
如果没有wspace=0.5,最后几行没有实际影响:
fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
#ratio=axes[0].get_position().width/w_pre_scl
#axlb=axl.get_position()
#axl.set_position([axlb.xmin, axlb.ymin, axlb.width, axlb.height*ratio])