<p dir="auto">When kwarg <code class="notranslate">depthshade</code> is <code class="notranslate">False</code>, the color of the points is seemingly random.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>

<p dir="auto">When kwarg <code class="notranslate">depthshade</code> is <code class="notranslate">False</code> in scatter3D, the color of the points is seemingly random. Using <code class="notranslate">depthshade=True</code> gives the correct colors.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-s1">backend</span> <span class="pl-c1">=</span> <span class="pl-s1">matplotlib</span>.<span class="pl-en">get_backend</span>()

<span class="pl-c"># to reproduce values</span>
<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">seed</span>(<span class="pl-c1">1234</span>)

<span class="pl-c"># 3D Gaussian distribution of points</span>
<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">normal</span>(<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-s1">size</span><span class="pl-c1">=</span>(<span class="pl-c1">3</span>,<span class="pl-c1">1000</span>))

<span class="pl-k">for</span> <span class="pl-s1">depthshade</span> <span class="pl-c1">in</span> [<span class="pl-c1">False</span>, <span class="pl-c1">True</span>]:
    <span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s">f'backend <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">backend</span><span class="pl-kos">}</span></span>, depthshade=<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">depthshade</span><span class="pl-kos">}</span></span>'</span>, <span class="pl-s1">clear</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">ax3d</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">gca</span>(<span class="pl-s1">projection</span><span class="pl-c1">=</span><span class="pl-s">'3d'</span>)
    <span class="pl-s1">ax3d</span>.<span class="pl-en">set</span>(<span class="pl-s1">title</span><span class="pl-c1">=</span><span class="pl-s">f'backend <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">backend</span><span class="pl-kos">}</span></span>, depthshade=<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">depthshade</span><span class="pl-kos">}</span></span>'</span>, 
             <span class="pl-s1">xlabel</span><span class="pl-c1">=</span><span class="pl-s">'x'</span>, <span class="pl-s1">ylabel</span><span class="pl-c1">=</span><span class="pl-s">'y'</span>, <span class="pl-s1">zlabel</span><span class="pl-c1">=</span><span class="pl-s">'z'</span>)
    
    <span class="pl-c"># color data according to z-coordinate</span>
    <span class="pl-s1">scatter</span> <span class="pl-c1">=</span> <span class="pl-s1">ax3d</span>.<span class="pl-en">scatter</span>(<span class="pl-c1">*</span><span class="pl-s1">data</span>, <span class="pl-s1">c</span><span class="pl-c1">=</span><span class="pl-s1">data</span>[<span class="pl-c1">2</span>], <span class="pl-s1">depthshade</span><span class="pl-c1">=</span><span class="pl-s1">depthshade</span>)
    
    <span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">scatter</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'z-coordinate'</span>)
    <span class="pl-s1">fig</span>.<span class="pl-en">tight_layout</span>()
    
    <span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/27952782/91016824-a9fa8980-e5ed-11ea-8a3e-6e0ce597e9cb.png"><img src="https://user-images.githubusercontent.com/27952782/91016824-a9fa8980-e5ed-11ea-8a3e-6e0ce597e9cb.png" alt="Qt5Agg_False" style="max-width: 100%;"></a><br>
With <code class="notranslate">depthshade=False</code> the color is assigned seemingly randomly.</p>
<p dir="auto"><strong>Expected outcome</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/27952782/91017952-3194c800-e5ef-11ea-9189-0caea4e2d032.png"><img src="https://user-images.githubusercontent.com/27952782/91017952-3194c800-e5ef-11ea-9189-0caea4e2d032.png" alt="Qt5Agg_True_linear" style="max-width: 100%;"></a><br>
With <code class="notranslate">depthshade=True</code> the color is assigned correctly.</p>
<p dir="auto">The problem appeared after I updated these packages from conda-forge:<br>
attrs                           19.3.0-py_0 --&gt; 20.1.0-pyh9f0ad1d_0<br>
matplotlib                        3.3.1-0 --&gt; 3.3.1-1<br>
matplotlib-base   3.3.1-py37h886f89f_0 --&gt; 3.3.1-py37h886f89f_1<br>
numpy              1.19.1-py37h1efc2f6_1 --&gt; 1.19.1-py37h1efc2f6_2<br>
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 <code class="notranslate">matplotlib._version.get_versions()</code> prints   <code class="notranslate">'full-revisionid': '079e015ccad39526098098c05b5e7e510fef19df'</code> with either build?)</p>
<p dir="auto">Sometimes (i.e. I have not managed to reproduce it reliably) the face- and edge-colors don't agree when <code class="notranslate">depthshade=True</code>.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: macOS 10.15.6 (19G2021)</li>
<li>Matplotlib version: 3.3.1-1 (from conda-forge)</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): tested in Qt5Agg and MacOSX</li>
<li>Python version: 3.7.8</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>

<p dir="auto">When colors are based on coordinates in <code class="notranslate">scatter3D</code>, the color changes when the orientation of the plot is changed.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>

<p dir="auto">This codes plots 10 points along the x-axis from 0 to <code class="notranslate">x_max</code>, using <code class="notranslate">scatter3D</code> with their color depending on their x-position (dark purple for 0, yellow for <code class="notranslate">x_max</code>).  The first <code class="notranslate">view_point</code> gives the expected result, whereas the second does not. For comparison, the same data plotted with <code class="notranslate">plot</code> (and offset by 1 in the z-direction for clarity) always give the expected result.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-s1">backend</span> <span class="pl-c1">=</span> <span class="pl-s1">matplotlib</span>.<span class="pl-en">get_backend</span>()

<span class="pl-c"># two view points to show the problem</span>
<span class="pl-s1">view_points</span> <span class="pl-c1">=</span> [[<span class="pl-c1">15</span>, <span class="pl-c1">-</span><span class="pl-c1">70</span>],[<span class="pl-c1">15</span>, <span class="pl-c1">-</span><span class="pl-c1">110</span>]]

<span class="pl-c"># create points along the x-axis</span>
<span class="pl-s1">num_points</span>, <span class="pl-s1">x_max</span> <span class="pl-c1">=</span> <span class="pl-c1">10</span>, <span class="pl-c1">4</span>
<span class="pl-s1">x_coord</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>, <span class="pl-s1">x_max</span>, <span class="pl-s1">num_points</span>)
<span class="pl-s1">y_coord</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros_like</span>(<span class="pl-s1">x_coord</span>)
<span class="pl-s1">z_coord</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros_like</span>(<span class="pl-s1">x_coord</span>)

<span class="pl-s1">coords_3d</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-s1">x_coord</span>, <span class="pl-s1">y_coord</span>, <span class="pl-s1">z_coord</span>])

<span class="pl-k">for</span> <span class="pl-s1">view_point</span> <span class="pl-c1">in</span> <span class="pl-s1">view_points</span>:

    <span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s">f'view point <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">view_point</span><span class="pl-kos">}</span></span>'</span>, <span class="pl-s1">clear</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">ax3d</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">gca</span>(<span class="pl-s1">projection</span><span class="pl-c1">=</span><span class="pl-s">'3d'</span>)
    <span class="pl-s1">ax3d</span>.<span class="pl-en">set_title</span>(<span class="pl-s">f'backend <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">backend</span><span class="pl-kos">}</span></span>, view point <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">view_point</span><span class="pl-kos">}</span></span>'</span>)
    
    <span class="pl-s1">ax3d</span>.<span class="pl-en">set_xlabel</span>(<span class="pl-s">'x'</span>)
    <span class="pl-s1">ax3d</span>.<span class="pl-en">set_ylabel</span>(<span class="pl-s">'y'</span>)
    <span class="pl-s1">ax3d</span>.<span class="pl-en">set_zlabel</span>(<span class="pl-s">'z'</span>)

    <span class="pl-c"># color points according to x-coordinate</span>
    <span class="pl-s1">scatter</span> <span class="pl-c1">=</span> <span class="pl-s1">ax3d</span>.<span class="pl-en">scatter3D</span>(<span class="pl-c1">*</span><span class="pl-s1">coords_3d</span>, <span class="pl-s1">c</span><span class="pl-c1">=</span><span class="pl-s1">x_coord</span>, <span class="pl-s1">depthshade</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)

    <span class="pl-c"># draw same points using `plot` and offset by 1 in z-direction for clarity</span>
    <span class="pl-k">for</span> <span class="pl-s1">coord</span> <span class="pl-c1">in</span> <span class="pl-s1">coords_3d</span>.<span class="pl-v">T</span>:
        <span class="pl-s1">ax3d</span>.<span class="pl-en">plot</span>(<span class="pl-c1">*</span><span class="pl-s1">coord</span> <span class="pl-c1">+</span> [<span class="pl-c1">0</span>,<span class="pl-c1">0</span>,<span class="pl-c1">1</span>], <span class="pl-s">'x'</span>,
                  <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s1">scatter</span>.<span class="pl-en">cmap</span>(<span class="pl-s1">scatter</span>.<span class="pl-en">norm</span>(<span class="pl-s1">coord</span>[<span class="pl-c1">0</span>])) )

    <span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">scatter</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'x-coordinate'</span>)

    <span class="pl-s1">ax3d</span>.<span class="pl-en">view_init</span>(<span class="pl-c1">*</span><span class="pl-s1">view_point</span>)

    <span class="pl-s1">ax3d</span>.<span class="pl-en">legend</span>(<span class="pl-s1">ax3d</span>.<span class="pl-en">get_children</span>()[:<span class="pl-c1">2</span>], [<span class="pl-s">'scatter'</span>,<span class="pl-s">'plot'</span>])
    <span class="pl-s1">fig</span>.<span class="pl-en">tight_layout</span>()
    <span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/27952782/90535991-c5900b00-e17b-11ea-959e-a25f4cf0cf01.png"><img src="https://user-images.githubusercontent.com/27952782/90535991-c5900b00-e17b-11ea-959e-a25f4cf0cf01.png" alt="Qt5Agg_-110" style="max-width: 100%;"></a></p>
<p dir="auto">The <code class="notranslate">view_point=[15,-110]</code> assigns the color in the wrong (reversed) order: the point at (0,0,0) has the bright color corresponding to an x-coordinate of <code class="notranslate">x_max</code>, which is clearly wrong. This occurs for azimuth angles between [-180,-90] and [90, 180] degrees.</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/27952782/90536018-cde84600-e17b-11ea-8687-5b793466fc40.png"><img src="https://user-images.githubusercontent.com/27952782/90536018-cde84600-e17b-11ea-8687-5b793466fc40.png" alt="Qt5Agg_-70" style="max-width: 100%;"></a></p>
<p dir="auto">The <code class="notranslate">view_point=[15,-70]</code> 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.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: maxOS 10.15.6 (19G2021)</li>
<li>Matplotlib version:  3.3.1</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): tested with Qt5Agg and MacOSX</li>
<li>Python version: 3.7.8</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>