在Matplotlib中给笛卡尔图添加极坐标轴

3
我已经按照这个问题中所述,在Matplotlib中绘制了一个极地等高线图。这基本上是通过将极坐标转换为笛卡尔坐标,然后在笛卡尔坐标系中绘制实现的。
然而,我想在图上叠加一组极坐标轴 - 即,在0、90、180和270度处有径向轴(从中心伸出),上面有刻度,显示各点的半径。
我完全不知道如何去做这件事,并且在文档中似乎找不到任何相关信息。有什么建议吗?
1个回答

2
fig   = plt.figure(0)
rect  = [0.1,0.1,0.8,0.8]
theta = np.linspace(0,2*np.pi,12)
line  = np.random.rand(5)
r     = np.linspace(1,1,12)

ax_carthesian = fig.add_axes(rect, ylim=(6.5,10.5), xlim=(-2,2), aspect='equal')
ax_carthesian.set_xlabel('X [kpc]')
ax_carthesian.set_ylabel('Y [kpc]')
# the polar axis:
ax_polar = fig.add_axes(rect, polar=True, frameon=False, xticks=([]), yticks=([]))
ax_polar.set_xticklabels(['','l=135','','l=225','','l=315','','l=45'])
ax_polar.set_yticklabels([]) #no radial ticks
# plotting on the carthesian axis
im = ax_carthesian.scatter(x_stuff, y_stuff, cmap='magma')
ax_polar.grid(True)
bothaxes = [ax_carthesian, ax_polar]
cbar     = plt.colorbar(im, ax = bothaxes)
cbar.ax.set_ylabel('Log I_CO [K]')

This is the resultant plot with both axes (and my X and Y data).


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接