8000 Scatter3D: facecolor or color to "none" leads to an error · Issue #18020 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
8000

Scatter3D: facecolor or color to "none" leads to an error #18020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cvanwynsberghe opened this issue Jul 22, 2020 · 6 comments
Closed

Scatter3D: facecolor or color to "none" leads to an error #18020

cvanwynsberghe opened this issue Jul 22, 2020 · 6 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: mplot3d
Milestone

Comments

@cvanwynsberghe
Copy link
cvanwynsberghe commented Jul 22, 2020

Assigning "none" to facecolor or color parameter does not work any longer for 3D scatter plots. My current version of matplotlib is 3.2.2

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

np.random.seed(2121)
x = np.random.randn(3, 10)

# %% 2D (still working)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(*x[0:2, :], marker='o', facecolor='blue', color='red', s=50)  # working
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(*x[0:2, :], marker='o', facecolor='none', color='red', s=50)   # working
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(*x[0:2, :], marker='o', facecolor='blue', color='none', s=50)   # working

# %% 3D (not working any longer)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor='blue', color='red', s=50)   # working
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor="none", color='red', s=50)   # NOT working
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor='blue', color="none", s=50)  # NOT working

The console returns the following error:

<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x7f668ea53b90>Traceback (most recent call last):
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 496, in _draw_idle
    self.draw()
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 393, in draw
    self.figure.draw(self.renderer)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py", line 1736, in draw
    renderer, self, artists, self.suppressComposite)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 137, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 293, in draw
    reverse=True)):
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 292, in <lambda>
    key=lambda col: col.do_3d_projection(renderer),
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 540, in do_3d_projection
    fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 847, in _zalpha
    rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
  File "<__array_function__ internals>", line 6, in broadcast_to
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 127, in _broadcast_to
    op_flags=['readonly'], itershape=shape, order='C')
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (0,4) and requested shape (10,4)
Traceback (most recent call last):
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 496, in _draw_idle
    self.draw()
  File "/home/vanwynch/anaconda3/lib/
8000
python3.7/site-packages/matplotlib/backends/backend_agg.py", line 393, in draw
    self.figure.draw(self.renderer)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py", line 1736, in draw
    renderer, self, artists, self.suppressComposite)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 137, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 293, in draw
    reverse=True)):
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 292, in <lambda>
    key=lambda col: col.do_3d_projection(renderer),
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 540, in do_3d_projection
    fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 847, in _zalpha
    rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
  File "<__array_function__ internals>", line 6, in broadcast_to
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/home/vanwynch/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 127, in _broadcast_to
    op_flags=['readonly'], itershape=shape, order='C')
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (0,4) and requested shape (10,4)

The workaround is to use (0, 0, 0, 0) as color/facecolor rather than "none" :

# %% 3D workaround
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor='blue', color='red', s=50)   # working
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor=(0, 0, 0, 0), color='red', s=50)   # working
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*x, marker='o', facecolor='blue', color=(0, 0, 0, 0), s=50)   # working
@QuLogic
Copy link
Member
QuLogic commented Jul 23, 2020

does not work any longer for 3D scatter plots. My current version of matplotlib is 3.2.2

And with which version did it previously work? Have you tried 3.3.0?

@mgeier
Copy link
Contributor
mgeier commented Jul 23, 2020

I've bisected the bug to 3f59cde (#13235).

However, I found this issue because I got a very similar error when using marker='x' (while other markers like marker='o' work fine), without using either color or facecolor at all. I was also using a 3D scatter plot.

I've bisected my problem (the one with marker='x') to d86cc2b (#17543).

@mgeier
Copy link
Contributor
mgeier commented Jul 23, 2020
8000

Here's how to reproduce the marker='x' problem:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

plt.gca(projection='3d')
plt.scatter([1], [1], [1], marker='x')
plt.show()
...
  File "[...]/lib/matplotlib/artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "[...]/lib/mpl_toolkits/mplot3d/axes3d.py", line 445, in draw
    sorted(self.collections,
  File "[...]/lib/mpl_toolkits/mplot3d/axes3d.py", line 446, in <lambda>
    key=lambda col: col.do_3d_projection(renderer),
  File "[...]/lib/mpl_toolkits/mplot3d/art3d.py", line 490, in do_3d_projection
    fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
  File "[...]/lib/mpl_toolkits/mplot3d/art3d.py", line 801, in _zalpha
    rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
  File "<__array_function__ internals>", line 5, in broadcast_to
  File "/usr/lib/python3/dist-packages/numpy/lib/stride_tricks.py", line 180, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/usr/lib/python3/dist-packages/numpy/lib/stride_tricks.py", line 123, in _broadcast_to
    it = np.nditer(
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (0,4) and requested shape (1,4)

@dstansby dstansby mentioned this issue Jul 25, 2020
@dstansby dstansby added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jul 25, 2020
@dstansby dstansby added this to the v3.3.1 milestone Jul 25, 2020
@dstansby
Copy link
Member

Thanks for the bisecting and reproducible example. I'm tagging this as release critical since it's basic behaviour that broke in 3.3.0.

@QuLogic
Copy link
Member
QuLogic commented Aug 4, 2020

Thanks for the bisecting and reproducible example. I'm tagging this as release critical since it's basic behaviour that broke in 3.3.0.

The bisect is to 3.1.0, so this is not a regression in 3.3.0. The second bisect was to a PR that was reverted for 3.3.0, so also not a regression.

@tacaswell
Copy link
Member

This works on the current default branch, I suspect by #18480.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: mplot3d
Projects
None yet
5 participants
0