-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Bug report
Bug summary
When the length of the color string passed into the bar3d function, matches the length of the
length of array x, it is treated as an array of N colors for coloring each bar individually (https://matplotlib.org/mpl_toolkits/mplot3d/api.html#mpl_toolkits.mplot3d.axes3d.Axes3D.bar3d), instead of as a single color for all bars.
Code for reproduction
import numpy as np
import matplotlib
import platform
import matplotlib.pyplot as plt
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
print("Matplotlib version: ", matplotlib.__version__)
print("Python version: ", platform.python_version())
# setup the figure and axes
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
# fake data
_x = np.arange(3)
_y = np.arange(2)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = x + y
bottom = np.zeros_like(top)
width = depth = 1
ax1.bar3d(x, y, bottom, width, depth, top, shade=True, color="orange")
# ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
plt.show()
Actual outcome
Traceback (most recent call last):
File "/Users/user/code/work/seistech/seistech_internal/seistech_internal/my_stuff/scratch.py", line 27, in <module>
ax1.bar3d(x, y, bottom, width, depth, top, shade=True, color="orange")
File "/Users/user/code/Envs/work/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 2566, in bar3d
sfacecolors = self._shade_colors(facecolors, normals)
File "/Users/user/code/Envs/work/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 1787, in _shade_colors
color = mcolors.to_rgba_array(color)
File "/Users/user/code/Envs/work/lib/python3.7/site-packages/matplotlib/colors.py", line 294, in to_rgba_array
result[i] = to_rgba(cc, alpha)
File "/Users/user/code/Envs/work/lib/python3.7/site-packages/matplotlib/colors.py", line 177, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "/Users/user/code/Envs/work/lib/python3.7/site-packages/matplotlib/colors.py", line 233, in _to_rgba_no_colorcycle
raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 'o'
Expected outcome
For the 3D bar plot to be created, with all bars colored orange. The above example works perfectly fine when no color or a color of length != 6 is used.
The problem is this line (https://github.com/matplotlib/matplotlib/blob/master/lib/mpl_toolkits/mplot3d/axes3d.py#L2417), which does not check that the input is an array (or not a string).
Matplotlib version
- Operating system: macOS Catalina (also tested on Ubuntu)
- Matplotlib version: 3.1.1
- Matplotlib backend: MacOSX
- Python version: 3.7.4
- Jupyter version (if applicable):
- Other libraries:
Run in a virtual environment with matplotlib installed using pip