Elena Greg
Elena Greg

Reputation: 1165

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

enter image description here

enter image description here

Upvotes: 1

Views: 72

Answers (1)

BenB
BenB

Reputation: 658

One solution to avoid this is to plot each point individually via

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. 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 might point you to a solution.

Upvotes: 1

Related Questions