重叠极数计数和散点图 [英] Overlapping polar countourf and scatter plot

查看:121
本文介绍了重叠极数计数和散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢此非常有用的 post ,我终于想出了如何制作极坐标填​​充轮廓图。但是,当我移到下一步并尝试向同一图上添加散点时,我遇到了一些问题。这是原始脚本:

Thanks to this very helpful post, I finally figured out how to make a polar filled-contour plot. However, when I moved to the next step and tried to add a scatter point to the same plot, I ran in some problems. Here is the original script:

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()

哪个生成了此图像:

Which produced this image:

如果我还添加一个散点图:

If I add also a scatter plot:

#-- 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')

我反而得到了这张图片:

I get instead this image:

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

Why do I get the thick white border between the filled contours and the axes? How do I get rid of it?

非常感谢!

推荐答案

抱歉,在问完我的问题两分钟后,我的回答很抱歉。我刚刚意识到,添加散点图会以某种方式更改轴限制。

Ops, sorry the answer occurred to me two minutes after a asked my question. I just realized that adding a scatter plot somehow changes the axes limits. Forcing the axes to the desired interval fixes the problem.

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)

我以为我仍然可以保留该问题,但对其他用户还是有帮助的。

I thought I could leave the question on anyways, it still can be helpful to other users.

这篇关于重叠极数计数和散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆