-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Milestone
Description
Bug report
Bug summary
shade
fails on a masked array. The offender seems to be intensity = np.clip(intensity, 0, 1)
in shade_normals
, as np.clip
returns a masked array with attribute mask=False
and shade_rgb
expects the mask attribute to be 2D.
Code for reproduction
import numpy as np
from matplotlib.colors import LightSource
import matplotlib.cm as cm
delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = Z1 - Z2
mask = np.zeros(Z.shape, dtype = bool)
Z = np.ma.masked_array(Z, mask = mask)
ls = LightSource(azdeg = 45., altdeg = 0.)
rgba = ls.shade(Z, cmap = cm.get_cmap())
Actual outcome
File "/Users/kpenner/anaconda3/envs/mpl/lib/python3.8/site-packages/matplotlib/colors.py", line 1869, in shade
rgb1 = self.shade_rgb(rgb0, elevation=data, blend_mode=blend_mode,
File "/Users/kpenner/anaconda3/envs/mpl/lib/python3.8/site-packages/matplotlib/colors.py", line 1943, in shade_rgb
mask = intensity.mask[..., 0]
IndexError: invalid index to scalar variable.
Expected outcome
Matplotlib version
- Matplotlib version: 3.2.1+2358.g9e20541c9
- Python version: 3.8
- numpy version: 1.18.4