开发者

Add polar axes to cartesian plot in Matplotlib

I have drawn a polar contour plot in Matplotlib as described in this question. This basically works by converting the polar co-ordinates to cartesian co-ordinates and then plotting in the cartesian co-ordinate system.

However, I want to be able to have a set of polar co-ordinate system axes overlain on the plot - that is, radial axes (sticking out from the centre) at 0, 90, 180 and 270 degrees, with ticks on them showing the radius at various points.

I have absolutely no idea开发者_开发知识库 how to go about doing this, and can't seem to find anything in documentation. Any suggestions?


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]')

Add polar axes to cartesian plot in Matplotlib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜