重叠极数与散点p

2024-09-28 22:29:28 发布

您现在位置:Python中文网/ 问答频道 /正文

多亏了这个非常有用的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

如果我还添加散点图:

^{pr2}$

取而代之的是这个图像:

Polar filled contour with scatter

为什么我得到填充轮廓和轴之间的厚白色边界?我怎样才能摆脱它?在

非常感谢!在


Tags: importsizeasnppltrandomaxpost
1条回答
网友
1楼 · 发布于 2024-09-28 22:29:28

抱歉,两分钟后,有人问我问题,我才想到答案。我刚刚意识到添加散点图会改变轴的限制。将轴强制到所需的间隔可解决问题。在

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

我想我可以把这个问题留着不管怎样,它仍然可以对其他用户有所帮助。在

相关问题 更多 >