gpt4 book ai didi

python - 重叠的极地乡村和散点图

转载 作者:太空宇宙 更新时间:2023-11-04 03:48:49 25 4
gpt4 key购买 nike

感谢这个很有帮助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

为什么我在填充的轮廓和轴之间得到白色的粗边框?我该如何摆脱它?

非常感谢!

最佳答案

糟糕,抱歉,我在问了我的问题两分钟后才想到答案。我刚刚意识到添加散点图会以某种方式改变轴限制。将轴强制设置为所需的间隔可以解决问题。

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

我想我还是可以留下这个问题,它仍然可以对其他用户有所帮助。

关于python - 重叠的极地乡村和散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22360421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com