Matplotlib 3D散点图α在查看不同角度时会有所不同

发布于 2025-01-21 22:00:47 字数 781 浏览 1 评论 0原文

当使用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.

enter image description hereenter image description here

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 技术交流群。

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

发布评论

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

评论(2

只涨不跌 2025-01-28 22:00:47

我还将其发布到 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.

烏雲後面有陽光 2025-01-28 22:00:47

一个可能的解决方法是为循环添加每个点,例如:

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)]

for x, y, z, s, a in zip(X, Y, Z, S, A):
    ax.scatter(xs=x, ys=y, zs=z, s=s, alpha=a, color="tab:blue")

plt.show()

One possible workaround is to add each point with a for loop, for example:

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)]

for x, y, z, s, a in zip(X, Y, Z, S, A):
    ax.scatter(xs=x, ys=y, zs=z, s=s, alpha=a, color="tab:blue")

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