Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb37db8

Browse files
committed
Updates based on feedback from @QuLogic
1 parent 23fb63c commit eb37db8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/matplotlib/colorizer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import numpy as np
2525
from numpy import ma
2626

27-
from matplotlib import _api, colors, cbook, artist, cm, scale
27+
from matplotlib import _api, colors, cbook, artist, scale
2828
import matplotlib as mpl
2929

3030
mpl._docstring.interpd.register(
@@ -222,9 +222,9 @@ def _set_cmap(self, cmap):
222222
in_init = self._cmap is None
223223
cmap_obj = _ensure_cmap(cmap, accept_multivariate=True)
224224
if not in_init and self.norm.n_components != cmap_obj.n_variates:
225-
raise ValueError(f"The colormap {cmap} does not support "
226-
f"{self.norm.n_components} variates as required by "
227-
f"the {type(self.norm)} on this Colorizer")
225+
raise ValueError(f"The colormap {cmap} does not support "
226+
f"{self.norm.n_components} variates as required by "
227+
f"the {type(self.norm)} on this Colorizer")
228228
self._cmap = cmap_obj
229229
if not in_init:
230230
self.changed() # Things are not set up properly yet.
@@ -814,7 +814,8 @@ def _ensure_cmap(cmap, accept_multivariate=False):
814814
if isinstance(cmap, types):
815815
return cmap
816816

817-
cmap_name = cmap if cmap is not None else mpl.rcParams["image.cmap"]
817+
cmap_name = mpl._val_or_rc(cmap, "image.cmap")
818+
818819
for mapping in mappings:
819820
if cmap_name in mapping:
820821
return mapping[cmap_name]
@@ -829,8 +830,6 @@ def _ensure_cmap(cmap, accept_multivariate=False):
829830
" `matplotlib.multivar_colormaps()` for"
830831
" bivariate and multivariate colormaps")
831832

832-
return cm.colormaps[cmap_name]
833-
834833

835834
def _ensure_multivariate_data(data, n_components):
836835
"""
@@ -870,7 +869,8 @@ def _ensure_multivariate_data(data, n_components):
870869
dt = np.dtype('float64, float64')
871870
else:
872871
dt = np.dtype('float32, float32')
873-
reconstructed = np.ma.frombuffer(data.data, dtype=dt).reshape(data.shape)
872+
873+
reconstructed = np.ma.array(np.asarray(data).view(dt))
874874
if np.ma.is_masked(data):
875875
for descriptor in dt.descr:
876876
reconstructed[descriptor[0]][data.mask] = np.ma.masked

lib/matplotlib/tests/test_colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,16 +2105,16 @@ def test_ensure_multivariate_data():
21052105
assert mdata.dtype.fields['f1'][0] == np.int64
21062106

21072107
# test input of floats, ints as tuple of lists
2108-
data = ([0.0, 0], [1, 1])
2108+
data = ([0.0, 0.0], [1, 1])
21092109
mdata = mcolorizer._ensure_multivariate_data(data, 2)
21102110
assert mdata.shape == (2,)
21112111
assert mdata.dtype.fields['f0'][0] == np.float64
21122112
assert mdata.dtype.fields['f1'][0] == np.int64
21132113

21142114
# test input of array of floats
2115-
data = np.array([[0.0, 0], [1, 1]])
2115+
data = np.array([[0.0, 0, 0], [1, 1, 1]])
21162116
mdata = mcolorizer._ensure_multivariate_data(data, 2)
2117-
assert mdata.shape == (2,)
2117+
assert mdata.shape == (3,)
21182118
assert mdata.dtype.fields['f0'][0] == np.float64
21192119
assert mdata.dtype.fields['f1'][0] == np.float64
21202120

0 commit comments

Comments
 (0)