Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Labels
Milestone
Description
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
importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dnp.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)# workingfig=plt.figure()ax=fig.add_subplot(111)ax.scatter(*x[0:2, :],marker='o',facecolor='none',color='red',s=50)# workingfig=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)# workingfig=plt.figure()ax=fig.add_subplot(111,projection='3d')ax.scatter(*x,marker='o',facecolor="none",color='red',s=50)# NOT workingfig=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/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 workaroundfig=plt.figure()ax=fig.add_subplot(111,projection='3d')ax.scatter(*x,marker='o',facecolor='blue',color='red',s=50)# workingfig=plt.figure()ax=fig.add_subplot(111,projection='3d')ax.scatter(*x,marker='o',facecolor=(0,0,0,0),color='red',s=50)# workingfig=plt.figure()ax=fig.add_subplot(111,projection='3d')ax.scatter(*x,marker='o',facecolor='blue',color=(0,0,0,0),s=50)# working