Matplotlib 3D散点图α在查看不同角度时会有所不同
当使用matplotlib创建3D散点图时,我注意到当点的alpha(透明度)变化时,它会根据您旋转视图的方式而绘制它们的不同。下面的示例图像略微旋转,这会导致alpha值神秘地逆转。有人熟悉这种行为以及如何解决吗?看起来“ Zorder”(Draw Order)是整个散点图调用的单个值。
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
X = [i for i in range(10)]
Y = [i for i in range(10)]
Z = [i for i in range(10)]
S = [(i+1)*400 for i in range(10)]
A = [i/10 for i in range(10)]
ax.scatter(xs=X, ys=Y, zs=Z, s=S, alpha=A)
plt.show()
-
-
When creating 3D scatter plots with matplotlib I noticed that when the alpha (transparency) of the points is varied it will draw them differently depending on how you rotate the view. The example images below are the same plot rotated slightly, which causes the alpha values to mysteriously reverse. Is anyone familiar with this behavior and how to address it? It looks like the 'zorder' (draw order) is a single value for the entire scatter plot call.
Simplified example code to recreate:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
X = [i for i in range(10)]
Y = [i for i in range(10)]
Z = [i for i in range(10)]
S = [(i+1)*400 for i in range(10)]
A = [i/10 for i in range(10)]
ax.scatter(xs=X, ys=Y, zs=Z, s=S, alpha=A)
plt.show()
- Python 3.9.5
- matplotlib 3.5.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还将其发布到 matplotlib github 看开发人员的想法。
根据他们的最新回答,这似乎是一个非常较低的问题:“ 我们的核心开发人员资源和MPL_Toolkits/mplot3d只是核心团队的次要优先级。很可能需要社区中的某人来选择“
我会尝试这样做,但是在此期间将其发布以供可见性,以便使其他具有更多经验的人都知道。
I also posted this on the matplotlib github to see what the developers think.
It appears to be a bug with a very low priority, per their latest response: "We have limited core developer resources and mpl_toolkits/mplot3d is only a secondary priority for the core team. Likely this needs someone in the community to pick up and provide a fix."
I will try to do so, but am posting this for visibility in the meantime so that other people with more experience are made aware.
一个可能的解决方法是为循环添加每个点,例如:
One possible workaround is to add each point with a
for
loop, for example: