重叠极坐标轮廓和散点图

时间:2014-03-12 18:18:04

标签: python matplotlib contour

感谢这个非常有帮助的post,我终于想出了如何制作极地填充轮廓图。但是,当我移动到下一步并试图在同一个图中添加一个散点时,我遇到了一些问题。这是原始脚本:

 
import numpy as np
import matplotlib.pyplot as plt

#-- Generate Data -----------------------------------------
# Using linspace so that the endpoint of 360 is included...
azimuths = np.radians(np.linspace(0, 360, 20))
zeniths = np.arange(0, 70, 10)

r, theta = np.meshgrid(zeniths, azimuths)
values = np.random.random((azimuths.size, zeniths.size))

#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)

plt.show()

哪个产生了这张图片: Polar filled contour without scatter

如果我还添加散点图:

#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
ax.scatter(np.radians(140), 40, s=20, c='White')

我得到了这张图片:

Polar filled contour with scatter

为什么在填充的轮廓和轴之间会出现厚白色边框?我该如何摆脱它?

非常感谢!

1 个答案:

答案 0 :(得分:2)

Ops,对不起,在问了我的问题后两分钟,我才回答。我刚刚意识到添加散点图会以某种方式改变轴的限制。将轴强制到所需的间隔可以解决问题。

fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
ax.scatter([np.radians(140)], [40], s=20, c='White')
ax.set_rmax(60)
ax.set_rmin(0)

enter image description here

我认为无论如何我都可以留下这个问题,它仍然可以对其他用户有所帮助。

相关问题