简体   繁体   English

python 中的立方体 - 散点颜色的设置

[英]Cube in python - setting of the color of scatter

How to prevent the scatters from changing the colour in dependence on the angle of view, please?请问如何防止散射根据视角改变颜色?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from itertools import product, combinations

fig = plt.figure(figsize=[10,6])
ax = fig.gca(projection='3d')
ax.azim = -112   # y rotation (default=270)
ax.elev = 31     # x rotation (default=0)

ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.2, 1, 1, 1]))

r = [-1, 1]
for s, e in combinations(np.array(list(product(r, r, r))), 2):
    if np.sum(np.abs(s-e)) == r[1]-r[0]:
        ax.plot3D(*zip(s, e), color='black', lw=1.5)

x_w = [0.5, 0.3]
y_w = [0, 0.6]
z_w = [0, -0.6]
ax.scatter(x_w, y_w, z_w, marker = 'o', s=500, facecolors=(0, 0, 0, 0), edgecolors = 'black')

ax._axis3don = False
plt.show()

在此处输入图像描述

在此处输入图像描述

One solution to avoid this is to plot each point individually via避免这种情况的一种解决方案是 plot 每个点分别通过

for i in range(len(x_w)):
    ax.scatter(x_w[i], y_w[i], z_w[i], marker = 'o', s=500, facecolors=(0, 0, 0, 0), edgecolors = 'black' )

If this is not an option for you, you may want to have a look into this or this thread.如果这不是你的选择,你可能想看看这个这个线程。 The argument depthshade = False may be the solution you are looking for.参数depthshade = False可能是您正在寻找的解决方案。 Unfortunately, I was unable to get the code to run with depthshade turned off.不幸的是,我无法在关闭depthshade的情况下运行代码。 It is not working for instances with more than one point in my matplotlib installation, but this link might point you to a solution.它不适用于在我的 matplotlib 安装中具有多个点的实例,但此链接可能会为您提供解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM