python - python 中的极地热图

标签 python python-3.x matplotlib heatmap polar-coordinates

我想将抛物面 f(r) = r**2 绘制为二维极地热图。我期望的输出是 enter image description here

我写的代码是

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

但是这个程序返回下面的图像。 enter image description here

有人可以帮忙吗?提前谢谢你。

最佳答案


[编辑] 感谢 Александр Рахмаев

Since version 3.3.3, the shading=flat (in pcolormesh by default) approach will give an error for the current data. I am using shanding=closest. Then there will be no error. Example: plt.pcolormesh(th, r, z, shading='nearest') See this also


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

这绘制了我认为你想要的:

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

enter image description here

如果你想要射线网格线,你可以按如下方式在每个 Theta 上添加它们:

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

enter image description here

还有更多像这样的径向网格:

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

enter image description here

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

关于python - python 中的极地热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36513312/

相关文章:

python - 从 jupyter notebook 调用在不同文件中编写的函数

Python3 : detect keypresses asynchronously and communicate them to the main thread

python - 为什么转置一个 numpy 数组将它旋转 90 度?

python - 应用 pandas df 中所有列的分布

python - 如果条目满足特定条件,则绘制函数 python

python - 我如何使用 __.init__ 并为 python 进行 OOP

python - 当多个值等于枢轴时,Hoare 分区不起作用

python - 如何在 scipy.stats 中指定泊松分布的尾部值?

python-3.x - 如何将 `directory` arg 传递给 Python 3 `http.server`?

用于读/写的 Python 3.3 Pickle 错误