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

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

问题描述

我正在使用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)

by

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散点图:后面的点与前面的点重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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