我创建了一个极坐标轮廓图并尝试通过将第一行的数据添加到结尾来关闭它。 在180度看到这张照片: PolarPlot
使用meshgrid和griddata模块创建数据。 数组大小为nxn类型。 例如: ri - float64 - (100,100)大小
print ri
[[ 0.00160738 0.00184056 0.00207375 ..., 0.23409252 0.23432571
0.23455889]
[ 0.00160738 0.00184056 0.00207375 ..., 0.23409252 0.23432571
0.23455889]
[ 0.00160738 0.00184056 0.00207375 ..., 0.23409252 0.23432571
0.23455889]
theta和contour创建等效。
绘图由matplotlib完成
我该怎么做?这是以180度“关闭”情节的正确方法吗?
以下是情节片段:
fig4 = plt.figure()
ax = fig4.add_subplot(111)
ax = plt.axes(polar=True)
image=plt.contourf(thetai,ri/d,contourd,128,vmin=0,extent=([-math.pi,+math.pi,min(ri[0]/d),max(ri[0]/d)]),cmap=plt.cm.Paired)
ax.set_xlabel(r'$\Theta$')
ax.set_ylabel(r'$r$')
答案 0 :(得分:2)
我不确定您的确切情节,但您可以使用numpy.pad
执行您描述的数组操作。
我们可以提供np.pad
原始数组和pad_width
((0,1),(0,1))
,这意味着左边是0位,右边是1,顶部是0列,1在底部。设置mode='edge'
以复制数组边缘的值。
例如:
In [16]: a = np.array([[1,1,5],[2,2,6],[7,8,9]])
In [17]: a
Out[17]:
array([[1, 1, 5],
[2, 2, 6],
[7, 8, 9]])
In [18]: np.pad(a,((0,1),(0,1)),mode='edge')
Out[18]:
array([[1, 1, 5, 5],
[2, 2, 6, 6],
[7, 8, 9, 9],
[7, 8, 9, 9]])
答案 1 :(得分:1)
从您的问题中,您的数据看起来并不清楚。
一般来说,对于要关闭的极坐标图,数据的最后一点必须与第一点相同。因此,如果你有一个数组X
,其中X[:,0]
是角度而X[:,1]
是半径,你可以通过将第一个元素附加到结尾来关闭极坐标图:
X_closed = np.append(X,X[[0]],axis = 0)
即。你只需要将第一行添加到结尾,而不是第一列。