Python 使用Matplotlib在极坐标系下的二维直方图,具有可变数量的存储单元

Python 使用Matplotlib在极坐标系下的二维直方图,具有可变数量的存储单元,python,matplotlib,Python,Matplotlib,我正在尝试使用Matplotlib创建极坐标系下的二维彩色直方图 料仓边缘沿径向轴均匀分布,但在给定半径下沿角度轴存在任意数量的料仓。 我尝试这样做是因为我希望垃圾箱的大小随着半径的增加而保持相对恒定。 所以在小半径下,只有几个角形垃圾箱,但在大半径下,会有更多 这是我第一次尝试使用pcolormesh(尽管对我来说有点复杂)。 正如您所看到的,由于网格线即使在极坐标中也保持笔直,因此箱边周围存在白色区域。(嗯,先给我发帖子,这样我就不能附加图片了。) 这是你的电话号码 有没有办法让白色区域消失

我正在尝试使用Matplotlib创建极坐标系下的二维彩色直方图

料仓边缘沿径向轴均匀分布,但在给定半径下沿角度轴存在任意数量的料仓。 我尝试这样做是因为我希望垃圾箱的大小随着半径的增加而保持相对恒定。 所以在小半径下,只有几个角形垃圾箱,但在大半径下,会有更多

这是我第一次尝试使用pcolormesh(尽管对我来说有点复杂)。 正如您所看到的,由于网格线即使在极坐标中也保持笔直,因此箱边周围存在白色区域。(嗯,先给我发帖子,这样我就不能附加图片了。)

这是你的电话号码

有没有办法让白色区域消失(最好是通过制作同心圆的箱子边缘)


可能最好使用
多个集合
,然后以这种方式绘制每个框。 import matplotlib.pyplot as plt import numpy as np

# bin properties in radial coordinate
nBins_r = 2 # number of bins in radial direction
r_max = 1.0
r_min = 0.0
delta_r = (r_max - r_min)/float(nBins_r) # size of increment in r

# bin properties in angular (theta) coordinate
nBins_theta_list = [] # number of bins depends on radius
delta_circumf = delta_r # set bin edge length same in both coordinates
circumf_max = 2.0*np.pi*r_max
nBins_theta_max = int(circumf_max/delta_circumf) # max number of bins in theta needed

# fill radial bin edges
binEdges_r = [0.0]
for i in xrange(nBins_r):
    binEdges_r.append(float(i+1)*delta_r)
    binEdges_r.append(float(i+1)*delta_r) # do twice for next bin in r
binEdges_r.pop() # last entry does not need to be repeated

# find size of array needed for angular bin edges, fill later
binEdges_theta = np.zeros(nBins_theta_max+1)

# create meshgrid
thetas, rs = np.meshgrid(binEdges_theta, binEdges_r, indexing='xy')

# fill matrix of angular bin edges
for i_r in xrange(nBins_r): # iterate through different r's
    r_edge = float(i_r+1)*delta_r # current radius
    circumf = 2.0*np.pi**r_edge # current circumference at radius r
    nBins_theta = int(circumf/delta_circumf) # number of bins in theta
    delta_theta = 2.0*np.pi/nBins_theta
    for i_theta in xrange(nBins_theta+1):
        thetas[2*i_r, i_theta] = i_theta*delta_theta - 0.5*delta_theta
        thetas[2*i_r+1, i_theta] = i_theta*delta_theta - 0.5*delta_theta # do twice for next bin in r
    nBins_theta_list.append(nBins_theta)

# weights of bins to be colored
w = np.full((2*nBins_r, nBins_theta_max), -1)

temp = 0.0
for i in xrange(nBins_r):
    for j in xrange(nBins_theta_list[i]):
        temp += 1
        w[2*i, j] = temp # set some arbitrary weight
ws = np.ma.masked_values(w, -1)

# create plot
ax = plt.subplot(projection="polar")
ax.pcolormesh(thetas, rs, ws)
plt.show()