在matplotlib中的极坐标图上设置径向偏移量

3

我有一些模拟数据,它们存储在一个2D的numpy数组中,大小类似于(512,768)。

这些数据是从rmin = 1到rmax = 100和phi从0到2pi模拟得到的。

我尝试在极坐标图上绘制这些数据,但是如果没有径向方向上的偏移,它看起来非常奇怪。注意:这些图像来自径向密度分布,所以绘图应该是径向对称的。

如果没有设置xlim/ylim:

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

rho = // 2D numpy array

ax.pcolormesh(rho)
fig.show()

没有偏移和xlim/ylim的径向图

设置了xlim/ylim:

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

rho = // 2D numpy array
print rho.shape

ax.axis([x_scale[0], x_scale[-1], y_scale[0], y_scale[-1]])

ax.pcolormesh(rho)
fig.show()

不带偏移的径向图

使用手动坐标轴和X/Y值。

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

rho = // 2D numpy array
print rho.shape

ax.axis([x_scale[0], x_scale[-1], 0, y_scale[-1]])
y_scale_with_offset = np.insert(y_scale, 0, 0)

ax.pcolormesh(x_scale, y_scale_with_offset, rho)

ax.pcolormesh(rho)

enter image description here

如何从1添加径向偏移?

1个回答

1

我相信您可以在极坐标图中使用ax.set_rmin(),负值将带给您所需的效果。

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

c = np.ones((50,50)) + np.arange(50).reshape(50,1)

aP = ax.pcolormesh(c)
plt.colorbar(aP)
ax.set_rmin(-10.0)
plt.show()

enter image description here

值得一提的是,加入一个刻度尺是有必要的,这样你就知道你不仅仅是从图表中删除数据(我假设这不是你的本意)。
顺便说一句,如果你还没有的话,你应该看看[ipython笔记本],因为当你输入ax.后按tab键,它会弹出一个可用对象列表,你可能已经能够找到解决问题的方法。由于matplotlib标签明确,set_rmin是一个相当明显的选择。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接