Python中的极坐标热图 [英] Polar heatmaps in python

查看:457
本文介绍了Python中的极坐标热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将抛物面f(r)= r ** 2绘制为二维极坐标热图.我期望的输出是

I want to plot a paraboloid f(r) = r**2 as a 2D polar heatmap. The output I expect is

我写的代码是

from pylab import*
from mpl_toolkits.mplot3d import Axes3D
ax = Axes3D(figure())
rad=linspace(0,5,100)
azm=linspace(0,2*pi,100)
r,th=meshgrid(rad,azm)
z=(r**2.0)/4.0
subplot(projection="polar")
pcolormesh(r,th, z)
show()

但是此程序返回以下图像.

But this program returns the following image.

有人可以帮忙吗?预先谢谢你.

Can someone help? Thank you in advance.

推荐答案

我认为您无意中混淆了radiuszenithazimuth:)

I think you inadvertently mixed up radius, zenith and azimuth :)

这说明了我想你想要的:

This plots what I think you want:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

fig = plt.figure()
ax = Axes3D(fig)

rad = np.linspace(0, 5, 100)
azm = np.linspace(0, 2 * np.pi, 100)
r, th = np.meshgrid(rad, azm)
z = (r ** 2.0) / 4.0

plt.subplot(projection="polar")

plt.pcolormesh(th, r, z)
#plt.pcolormesh(th, z, r)

plt.plot(azm, r, color='k', ls='none') 
plt.grid()

plt.show()

如果要使用射线网格线,可以按如下所示在每个Theta中添加它们:

If you want ray grid lines, you can add them every Theta as follows:

plt.thetagrids([theta * 15 for theta in range(360//15)])

还有更多类似的径向网格:

and more radial grids like this:

plt.rgrids([.3 * _ for _ in range(1, 17)])

PS:numpy和pyplot将使您的命名空间保持整洁...

PS: numpy and pyplot will keep your namespace tidy...

这篇关于Python中的极坐标热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆