如何从散点图中排除x = 0或y = 0值?

发布于 2025-01-17 21:31:54 字数 543 浏览 2 评论 0原文

我有一个看起来像这样的散点图:

”在此处输入图像描述

我正在尝试制作它,以便如果x = 0或y = 0,那么散布点就被忽略了,只有x和y的值 等于零:

既大于或 net/lohuv.png“ alt =”在此处输入图像描述>

这是我到目前为止尝试的:

x = df['tp']
y = df['tp1']

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


plt.scatter(x,y)

我对此遇到以下内容:

ValueError: x and y must be the same size

有理由是有理由我可以使用的另一种解决方案?

I have a scatter graph that looks like this:

enter image description here

I'm trying to make it so that if x=0 or y=0 then that scatter point is ignored, and only the values where x and y are both greater than or equal to zero are taken:

enter image description here

Here's what I've tried so far:

x = df['tp']
y = df['tp1']

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


plt.scatter(x,y)

To which I get met with the following:

ValueError: x and y must be the same size

Is there a reason for why this isn't working, or a different solution that I could use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

思慕 2025-01-24 21:31:54

过滤时,您正在更改过滤器的上下文,但是可以做:

x_filtered = x[ (x > 0.0) and (y> 0.0)]
y_filtered  = y[ (x > 0.0) and (y> 0.0)]

plt.scatter(x_filtered ,y_filtered)

You are changing the context of the filter while filtering, but you can do:

x_filtered = x[ (x > 0.0) and (y> 0.0)]
y_filtered  = y[ (x > 0.0) and (y> 0.0)]

plt.scatter(x_filtered ,y_filtered)
流殇 2025-01-24 21:31:54

问题是您需要将同时排除x s和y s,其中一个是0

想象一下,xy中的5中有10, 0 s。您的Xy大小不会相同。更重要的是,您将有错误的对Xy s。

你需要什么?

查找xy拒绝蒙版,然后将它们应用于x an y s::

x = df['tp']
y = df['tp1']

xy_mask = x > 0.0 and y > 0.0

x = x[xy_mask]
y = y[xy_mask]

plt.scatter(x,y)

The problem is you need to exclude both xs and ys where either one is 0.

Imagine you have 10, 0s in x and 5 in y. Your x and y size would not be the same. And more importantly you'll have wrong pairs of x and ys.

What you need?

find x and y rejection masks then apply them to both x an ys:

x = df['tp']
y = df['tp1']

xy_mask = x > 0.0 and y > 0.0

x = x[xy_mask]
y = y[xy_mask]

plt.scatter(x,y)
心清如水 2025-01-24 21:31:54

此链接中已经给出了类似的答案。我希望它能帮助你。

不在 matplotlib 中绘制“零”或更改零为无 [Python]

A similar answer is already given in this link. I hope it will help you out.

Not plotting 'zero' in matplotlib or change zero to None [Python]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文