如何从散点图中排除x = 0或y = 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:
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
过滤时,您正在更改过滤器的上下文,但是可以做:
You are changing the context of the filter while filtering, but you can do:
问题是您需要将同时排除
x
s和y
s,其中一个是0
。想象一下,
x
和y
中的5中有10, 0 s。您的X
和y
大小不会相同。更重要的是,您将有错误的对X
和y
s。你需要什么?
查找
x
和y
拒绝蒙版,然后将它们应用于x
any
s::The problem is you need to exclude both
x
s andy
s where either one is0
.Imagine you have 10,
0
s inx
and 5 iny
. Yourx
andy
size would not be the same. And more importantly you'll have wrong pairs ofx
andy
s.What you need?
find
x
andy
rejection masks then apply them to bothx
any
s:此链接中已经给出了类似的答案。我希望它能帮助你。
不在 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]