Issue 1:
When kwarg depthshade is False, the color of the points is seemingly random.

Bug report

Bug summary

When kwarg depthshade is False in scatter3D, the color of the points is seemingly random. Using depthshade=True gives the correct colors.

Code for reproduction

import numpy as np
import matplotlib
from matplotlib import pyplot as plt
backend = matplotlib.get_backend()

# to reproduce values
np.random.seed(1234)

# 3D Gaussian distribution of points
data = np.random.normal(0, 1, size=(3,1000))

for depthshade in [False, True]:
fig = plt.figure(f'backend {backend}, depthshade={depthshade}', clear=True)
ax3d = fig.gca(projection='3d')
ax3d.set(title=f'backend {backend}, depthshade={depthshade}',
xlabel='x', ylabel='y', zlabel='z')

# color data according to z-coordinate
scatter = ax3d.scatter(*data, c=data[2], depthshade=depthshade)

fig.colorbar(scatter, label='z-coordinate')
fig.tight_layout()

plt.show()

Actual outcome

With depthshade=False the color is assigned seemingly randomly.

Expected outcome

With depthshade=True the color is assigned correctly.

The problem appeared after I updated these packages from conda-forge:

attrs 19.3.0-py_0 --> 20.1.0-pyh9f0ad1d_0

matplotlib 3.3.1-0 --> 3.3.1-1

matplotlib-base 3.3.1-py37h886f89f_0 --> 3.3.1-py37h886f89f_1

numpy 1.19.1-py37h1efc2f6_1 --> 1.19.1-py37h1efc2f6_2

The problem persisted after I reverted back to matplotlib 3.3.1-0 and matplotlib-base 3.3.1-py37h886f89f_0. (Maybe I did not revert back to the old version, since matplotlib._version.get_versions() prints 'full-revisionid': '079e015ccad39526098098c05b5e7e510fef19df' with either build?)

Sometimes (i.e. I have not managed to reproduce it reliably) the face- and edge-colors don't agree when depthshade=True.

Matplotlib version

Operating system: macOS 10.15.6 (19G2021)

Matplotlib version: 3.3.1-1 (from conda-forge)

Matplotlib backend (print(matplotlib.get_backend())): tested in Qt5Agg and MacOSX

Python version: 3.7.8

Jupyter version (if applicable):

Other libraries:

Issue 2:
Bug report

Bug summary

When colors are based on coordinates in scatter3D, the color changes when the orientation of the plot is changed.

Code for reproduction

This codes plots 10 points along the x-axis from 0 to x_max, using scatter3D with their color depending on their x-position (dark purple for 0, yellow for x_max). The first view_point gives the expected result, whereas the second does not. For comparison, the same data plotted with plot (and offset by 1 in the z-direction for clarity) always give the expected result.

import numpy as np
from matplotlib import pyplot as plt

import matplotlib
backend = matplotlib.get_backend()

# two view points to show the problem
view_points = [[15, -70],[15, -110]]

# create points along the x-axis
num_points, x_max = 10, 4
x_coord = np.linspace(0, x_max, num_points)
y_coord = np.zeros_like(x_coord)
z_coord = np.zeros_like(x_coord)

coords_3d = np.array([x_coord, y_coord, z_coord])

for view_point in view_points:

fig = plt.figure(f'view point {view_point}', clear=True)
ax3d = fig.gca(projection='3d')
ax3d.set_title(f'backend {backend}, view point {view_point}')

ax3d.set_xlabel('x')
ax3d.set_ylabel('y')
ax3d.set_zlabel('z')

# color points according to x-coordinate
scatter = ax3d.scatter3D(*coords_3d, c=x_coord, depthshade=False)

# draw same points using `plot` and offset by 1 in z-direction for clarity
for coord in coords_3d.T:
ax3d.plot(*coord + [0,0,1], 'x',
color=scatter.cmap(scatter.norm(coord[0])) )

fig.colorbar(scatter, label='x-coordinate')

ax3d.view_init(*view_point)

ax3d.legend(ax3d.get_children()[:2], ['scatter','plot'])
fig.tight_layout()
plt.show()

Actual outcome

The view_point=[15,-110] assigns the color in the wrong (reversed) order: the point at (0,0,0) has the bright color corresponding to an x-coordinate of x_max, which is clearly wrong. This occurs for azimuth angles between [-180,-90] and [90, 180] degrees.

Expected outcome

The view_point=[15,-70] produces the expected outcome, i.e. dark colors for points close to the origin at (0,0,0) and bright colors for points farther away. This should be independent on the orientation of the plot.

Matplotlib version

Operating system: maxOS 10.15.6 (19G2021)

Matplotlib version: 3.3.1

Matplotlib backend (print(matplotlib.get_backend())): tested with Qt5Agg and MacOSX

Python version: 3.7.8

Jupyter version (if applicable):

Other libraries: