Pyplot 3d scatter:后面的点重叠前面的点 [英] Pyplot 3d scatter: points at the back overlap points at the front

查看:98
本文介绍了Pyplot 3d scatter:后面的点重叠前面的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 matplotlib 准备 3d 图,并且我在处理多个数据集时出现了非常奇怪的行为.我有两个数据集,基本上描述了 3d 中的两个壳:一个内壳和一个外壳.要在 3d 中绘制它们,我会这样做:

I am preparing 3d plots with matplotlib and I am having a really weird behaviour with multiple datasets. I have two datasets that describe basically two shells in 3d: one inner shell and one outer shell. To plot them in 3d I do:

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')    

ax.scatter(outer_z[:n], outer_x[:n], outer_y[:n], c='black', marker='.', lw=0)
ax.scatter(inner_z[:n],  inner_x[:n], inner_y[:n], c='red', marker='.', lw=0)

ax.set_xlabel("Z")
ax.set_ylabel("X")
ax.set_zlabel("Y")

ax.set_xlim([-5,5])
ax.set_ylim([5,-5])
ax.set_zlim([-5,5])

(轴的顺序仅用于透视目的).但是,当我保存图形时,我没有得到两个外壳:

(the order of the axes are just for perspective purposes). When I save the figure, however, I don't get two shells:

我把一层放在另一层上,明显在后面的点出现在前面.你可以在图片上看到,外壳的一些应该在内壳后面的点被绘制在内壳前面.这真的很烦人,因为它不追求3d 情节"的目的.有没有人知道为什么会发生这种情况以及如何解决?非常感谢!

I get one layer over the other, with the points that are clearly in the back appearing in front. You can see on the pictures that some points of the outer shell that should be behind the inner shell are plotted in front of the inner shell. This is really annoying, because it does not pursue the "plot in 3d" purpose. Does any one have an idea on why is this happening and how could this be solved? Many thanks!

推荐答案

非常感谢您的解释 :) 我认为它确实可能是这样的.但是我忘了在我的问题中说,无论 ax.scatter 命令的顺序如何,都会发生同样的事情,这很奇怪.在阅读您的答案之前,我发现 ax.plot 命令不会发生这种情况.因此,我替换了:

thanks you so much for your explanation :) I thought it could be something like that indeed. But I forgot to say in my question that the same thing happened no matter the order of the ax.scatter commands, what is pretty weird. I found out before reading your answer that that does not happen with the ax.plot command. Therefore, I replaced:

ax.scatter(outer_z[:n], outer_x[:n], outer_y[:n], c='black', marker='.', lw=0)
ax.scatter(inner_z[:n],  inner_x[:n], inner_y[:n], c='red', marker='.', lw=0)

ax.plot(outer_z[:n],  outer_x[:n], outer_y[:n], '.', markersize=1, color='black') 
ax.plot(inner_z[:n], inner_x[:n], inner_y[:n], '.', markersize=1, color='red') 

我得到了以下图片:

这对我有用.然而,我知道,如果我改变观点,我会看到红色外壳出现在黑色外壳之上.我后来发现的一个问题是 .plot 函数没有 vmin 和 vmax 参数(作为 .scatter 参数),这使得将颜色定义为从 vmin 和 vmax 开始的渐变变得更加困难...

which works for me. I know, however, that if I change the point of view I will have the red shell appearing on top of the black one. One problem I found later was that the .plot function does not have vmin and vmax arguments (as the .scatter one), which makes it harder to define the color as a gradient starting in vmin and vmax...

这篇关于Pyplot 3d scatter:后面的点重叠前面的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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