在 Matplotlib 中将极轴添加到笛卡尔图

发布于 2024-11-18 07:34:35 字数 297 浏览 1 评论 0原文

我已经在 Matplotlib 中绘制了极坐标等高线图,如这个问题中所述。这基本上是通过将极坐标转换为笛卡尔坐标,然后在笛卡尔坐标系中绘图来实现的。

但是,我希望能够在绘图上覆盖一组极坐标系轴 - 即 0、90、180 和 270 度的径向轴(从中心伸出),并在其上显示刻度不同点处的半径。

我完全不知道如何去做这件事,并且似乎在文档中找不到任何内容。有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人 2024-11-25 07:34:35
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]')

这是带有两个轴的结果图(以及我的 X 和 Y 数据)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文