[英]Matplotlib density plot in polar coordinates?
I have an array saved as a txt file that has entries corresponding to the value of a distribution in polar coordinates.我有一个保存为 txt 文件的数组,其中的条目与极坐标中的分布值相对应。 So it looks like this:所以它看起来像这样:
f(r1,theta1) f(r1, theta2) ..... f(r1, theta_max)
f(r2,theta1) f(r2, theta2) ..... .
. .
. .
. .
f(r_max,theta1) .................f(r_max, theta_max)
I want to do a density plot of f (the higher f is, the more red I want the color to be).我想做一个 f 的密度图(f 越高,我想要颜色越红)。 Is there a way to do this with matplotlib?有没有办法用 matplotlib 做到这一点? Explicit code would be helpful, as I am majorly new to this.显式代码会有所帮助,因为我对此非常陌生。
In this example, a
is you theta1...thetan, b
is your r1...rn, c
is your f(a, b):在这个例子中, a
是你的 theta1...thetan, b
是你的 r1...rn, c
是你的 f(a, b):
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
#fake data:
a = np.linspace(0,2*np.pi,50)
b = np.linspace(0,1,50)
A, B = np.meshgrid(a, b)
c = np.random.random(A.shape)
#actual plotting
ax = plt.subplot(111, polar=True)
ax.set_yticklabels([])
ctf = ax.contourf(a, b, c, cmap=cm.jet)
plt.colorbar(ctf)
Essentially a filled contour plot in polar axis.本质上是极轴上的填充等高线图。 You can specify alternative colormap with the cmap=...
.您可以使用cmap=...
指定替代颜色图。 cm.jet
goes from blue to red, with red being the largest value. cm.jet
从蓝色变为红色,红色是最大值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.