忽略绘制特定值的数据点 [英] Ignoring plotting data points of certain value

查看:30
本文介绍了忽略绘制特定值的数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的图,我试图找出一种方法来忽略 x 值 = 0.0 的绘图点.基本上,我希望我的情节不包括您在左上角看到的那 3 个点.

I have a plot shown below and I am trying to figure out a way to ignore plotting points that have x value = 0.0. Basically, I want my plot to not include those 3 points you see in the top left corner.

y = np.array([4.7, 6.6, 6.4, 6.8, 6.2, 7.2, 6.1, 5.9, 6.4, 6.6])
x = np.array([0.405,0.0,1.254,1.096,1.128,0.0,0.828,1.083,1.309,0.0])

plt.scatter(x, y)

推荐答案

有两种方法,取决于您是要实际停止绘制它们,还是只是停止显示它们.

There are two ways, depending on whether you want to actually stop plotting them, or just stop showing them.

第一个是只设置 x 轴的限制,以便这些点不可见.在你的脚本结束时,你可以做

The first is to just set the limits of the x-axis so that those points aren't visible. At the end of your script, you can do

plt.xlim(left=0.3)

另一种方法是在绘图之前从数据中实际删除这些点.为此:

The other method is to actually cut those points out of the data before plotting. To do this:

x = x[x > 0.0]
y = y[x > 0.0]

plt.scatter(x, y)

请注意,在这两种情况下,我们都是通过 x > 进行索引的.0.0 只删除 x 值为 0 的点(y 值可以是任何值).

Note that in both cases, we're indexing by x > 0.0 to cut out only the points for which the x value is 0 (the y values could be anything).

这篇关于忽略绘制特定值的数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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