python 中的极地热图
Polar heatmaps in python
我想将抛物面 f(r) = r**2 绘制为二维极地热图。我期望的输出是
我写的代码是
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()
但是这个程序returns如下图。
有人可以帮忙吗?提前谢谢你。
[编辑] 感谢 Александр Рахмаев
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
我认为你无意中混淆了 radius
、zenith
和 azimuth
:)
这是我认为你想要的情节:
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()
如果你想要射线网格线,你可以按如下方式添加它们:
plt.thetagrids([theta * 15 for theta in range(360//15)])
还有更多像这样的径向网格:
plt.rgrids([.3 * _ for _ in range(1, 17)])
PS: numpy 和 pyplot 将使您的命名空间保持整洁...
我想将抛物面 f(r) = r**2 绘制为二维极地热图。我期望的输出是
我写的代码是
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()
但是这个程序returns如下图。
有人可以帮忙吗?提前谢谢你。
[编辑] 感谢 Александр Рахмаев
Since version 3.3.3, the
shading=flat
(inpcolormesh
by default) approach will give an error for the current data. I am usingshanding=closest
. Then there will be no error. Example:plt.pcolormesh(th, r, z, shading='nearest')
See this also
我认为你无意中混淆了 radius
、zenith
和 azimuth
:)
这是我认为你想要的情节:
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()
如果你想要射线网格线,你可以按如下方式添加它们:
plt.thetagrids([theta * 15 for theta in range(360//15)])
还有更多像这样的径向网格:
plt.rgrids([.3 * _ for _ in range(1, 17)])
PS: numpy 和 pyplot 将使您的命名空间保持整洁...