Cube in python - 散点颜色设置
Cube in python - setting of the color of scatter
请问如何防止散点随视角改变颜色?
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()
避免这种情况的一种解决方案是通过
单独绘制每个点
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' )
如果这不适合您,您可能需要查看 this or this thread. The argument depthshade = False
may be the solution you are looking for. Unfortunately, I was unable to get the code to run with depthshade
turned off. It is not working for instances with more than one point in my matplotlib installation, but this link 可能会为您提供解决方案。
请问如何防止散点随视角改变颜色?
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()
避免这种情况的一种解决方案是通过
单独绘制每个点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' )
如果这不适合您,您可能需要查看 this or this thread. The argument depthshade = False
may be the solution you are looking for. Unfortunately, I was unable to get the code to run with depthshade
turned off. It is not working for instances with more than one point in my matplotlib installation, but this link 可能会为您提供解决方案。