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

Skip to content

Commit 2f8b5bf

Browse files
committed
fix failing commits
1 parent b44a511 commit 2f8b5bf

5 files changed

Lines changed: 22 additions & 118 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,17 +3979,6 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
39793979
else:
39803980
try:
39813981
c_array = np.asanyarray(c, dtype=float)
3982-
if c_array.ndim > 1:
3983-
if cmap is None:
3984-
cmap = mcolors.BivariateColormap()
3985-
if norm is None:
3986-
norm = mcolors.BivariateNorm()
3987-
c_array = norm(c_array)
3988-
c_array[0] = c_array[0] * (cmap.N-1)
3989-
c_array[1] = c_array[1] * (cmap.N-1)
3990-
c_array = c_array.astype(int)
3991-
c_array = c_array[0] + cmap.N * c_array[1]
3992-
norm = mcolors.NoNorm()
39933982
if c_array.shape in xy_shape:
39943983
c = np.ma.ravel(c_array)
39953984
else:
@@ -4054,10 +4043,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
40544043
collection.update(kwargs)
40554044

40564045
if colors is None:
4057-
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
4058-
if norm is not None and not isNorm:
4059-
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
4060-
"or 'mcolors.BivariateNorm'"
4046+
if norm is not None and not isinstance(norm, mcolors.Normalize):
4047+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
40614048
raise ValueError(msg)
40624049
collection.set_array(np.asarray(c))
40634050
collection.set_cmap(cmap)
@@ -5133,6 +5120,11 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51335120
51345121
"""
51355122

5123+
temp = np.asarray(X)
5124+
if temp.ndim == 3 and isinstance(norm, mcolors.BivariateNorm):
5125+
temp = norm(temp)
5126+
X = cmap(temp, alpha=self.get_alpha(), bytes=True)
5127+
51365128
if not self._hold:
51375129
self.cla()
51385130

@@ -5146,21 +5138,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51465138
aspect = rcParams['image.aspect']
51475139
self.set_aspect(aspect)
51485140

5149-
temp = np.asarray(X)
5150-
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
5151-
isinstance(cmap, mcolors.BivariateColormap))
5152-
if (temp.ndim == 3 and isBivari):
5153-
if cmap is None:
5154-
cmap = mcolors.BivariateColormap()
5155-
if norm is None:
5156-
norm = mcolors.BivariateNorm()
5157-
temp = norm(temp)
5158-
temp[0] = temp[0] * (cmap.N-1)
5159-
temp[1] = temp[1] * (cmap.N-1)
5160-
temp = temp.astype(int)
5161-
X = temp[0] + cmap.N * temp[1]
5162-
norm = mcolors.NoNorm()
5163-
51645141
im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
51655142
filternorm=filternorm, filterrad=filterrad,
51665143
resample=resample, **kwargs)
@@ -5201,10 +5178,10 @@ def _pcolorargs(funcname, *args, **kw):
52015178
allmatch = kw.pop("allmatch", False)
52025179
norm = kw.pop("norm", None)
52035180
cmap = kw.pop("cmap", None)
5181+
alpha = kw.pop("alpha", 1)
52045182

52055183
if len(args) == 1:
52065184
C = np.asanyarray(args[0])
5207-
52085185
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
52095186
isinstance(cmap, mcolors.BivariateColormap))
52105187
if (C.ndim == 3 and isBivari):
@@ -5213,12 +5190,6 @@ def _pcolorargs(funcname, *args, **kw):
52135190
if norm is None:
52145191
norm = mcolors.BivariateNorm()
52155192
C = norm(C)
5216-
C[0] = C[0] * (cmap.N-1)
5217-
C[1] = C[1] * (cmap.N-1)
5218-
C = C.astype(int)
5219-
C = C[0] + cmap.N * C[1]
5220-
C = np.array(C)
5221-
52225193
numRows, numCols = C.shape
52235194
if allmatch:
52245195
X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
@@ -5238,11 +5209,6 @@ def _pcolorargs(funcname, *args, **kw):
52385209
if norm is None:
52395210
norm = mcolors.BivariateNorm()
52405211
C = norm(C)
5241-
C[0] = C[0] * (cmap.N-1)
5242-
C[1] = C[1] * (cmap.N-1)
5243-
C = C.astype(int)
5244-
C = C[0] + cmap.N * C[1]
5245-
C = np.array(C)
52465212
numRows, numCols = C.shape
52475213
else:
52485214
raise TypeError(
@@ -5794,19 +5760,11 @@ def pcolorfast(self, *args, **kwargs):
57945760
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
57955761
isinstance(cmap, mcolors.BivariateColormap))
57965762
if (C.ndim == 3 and isBivari):
5797-
if cmap is None:
5798-
cmap = mcolors.BivariateColormap()
5799-
if norm is None:
5800-
norm = mcolors.BivariateNorm()
58015763
C = norm(C)
5802-
C[0] = C[0] * (cmap.N-1)
5803-
C[1] = C[1] * (cmap.N-1)
5804-
C = C.astype(int)
5805-
C = C[0] + cmap.N * C[1]
5806-
C = np.array(C)
5807-
norm = mcolors.NoNorm()
5808-
5809-
nr, nc = C.shape
5764+
nr, nc = C.shape
5765+
C = cmap(C, alpha=alpha, bytes=True)
5766+
else:
5767+
nr, nc = C.shape
58105768
if len(args) == 1:
58115769
style = "image"
58125770
x = [0, nc]

lib/matplotlib/cm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ def __init__(self, norm=None, cmap=None):
201201
#: The Normalization instance of this ScalarMappable.
202202
self.norm = norm
203203
#: The Colormap instance of this ScalarMappable.
204-
# self.cmap = get_cmap(cmap)
205-
self.cmap = cmap
204+
self.cmap = get_cmap(cmap)
206205
#: The last colorbar associated with this ScalarMappable. May be None.
207206
self.colorbar = None
208207
self.update_dict = {'array': False}

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ def _edges(self, X, Y):
10811081
'''
10821082
Return the separator line segments; helper for _add_solids.
10831083
'''
1084-
N = X.shape[0].
1084+
N = X.shape[0]
10851085
return [list(zip(X[i], Y[i])) for i in xrange(1, N - 1)]
10861086
+ [list(zip(Y[i], X[i])) for i in xrange(1, N - 1)]
10871087

@@ -1159,7 +1159,8 @@ def _ticker(self, norm):
11591159
if mpl.rcParams['_internal.classic_mode']:
11601160
locator = ticker.MaxNLocator()
11611161
else:
1162-
locator = ticker.AutoLocator()
1162+
# locator = ticker.AutoLocator()
1163+
locator = ticker.MaxNLocator(nbins=5)
11631164
else:
11641165
b = _boundaries[self._inside]
11651166
locator = ticker.FixedLocator(b, nbins=10)

lib/matplotlib/colors.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,22 +1414,13 @@ def __call__(self, values, clip=None):
14141414
if clip is None:
14151415
clip = [self.norm1.clip, self.norm2.clip]
14161416

1417-
return np.asarray([self.norm1(values[0], clip=clip[0]),
1418-
self.norm2(values[1], clip=clip[1])])
1417+
temp = np.asarray([self.norm1(values[0], clip=clip[0]),
1418+
self.norm2(values[1], clip=clip[1])])
14191419

1420-
def inverse(self, values):
1421-
"""
1422-
Parameters
1423-
----------
1424-
values : array-like
1425-
A list of two values to be inverted
1426-
1427-
Returns
1428-
-------
1429-
A list of two unnormalized values
1430-
"""
1431-
return np.asarray([self.norm1.inverse(values[0]),
1432-
self.norm2.inverse(values[1])])
1420+
temp[0] = temp[0] * (256)
1421+
temp[1] = temp[1] * (256)
1422+
temp = temp.astype(int)
1423+
return temp[0] + temp[1] * 256
14331424

14341425
def autoscale(self, A):
14351426
"""

lib/matplotlib/tests/test_colors.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -272,51 +272,6 @@ def _mask_tester(norm_instance, vals):
272272
masked_array[0] = np.ma.masked
273273
assert_array_equal(masked_array.mask, norm_instance(masked_array).mask)
274274

275-
@pytest.mark.parametrize(
276-
'norm1, norm2, values, expected, clip', [
277-
(
278-
None,
279-
None,
280-
[[0.2, 0.4, 0.5], [5, 7, 9, 10]],
281-
[[0, 0.666667, 1], [0, 0.4, 0.8, 1]],
282-
None
283-
),
284-
(
285-
mcolors.LogNorm(clip=True, vmax=5),
286-
None,
287-
[[1, 6], [5, 7, 9, 10]],
288-
[[0, 1.0], [0, 0.4, 0.8, 1]],
289-
None
290-
),
291-
(
292-
mcolors.PowerNorm(2, vmin=0, vmax=8, clip=None),
293-
mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True),
294-
[np.array([-0.5, 0, 2, 4, 8], dtype=float),
295-
np.array([-0.5, 0, 1, 8, 16], dtype=float)],
296-
[[0, 0, 1/16, 1/4, 1], [0, 0, 0, 1, 1]],
297-
None
298-
),
299-
(
300-
mcolors.SymLogNorm(3, vmin=-30, vmax=5, linscale=1.2),
301-
mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False),
302-
[np.array([-30, -1, 2, 6], dtype=float),
303-
np.array([-0.5, 0, 1, 8, 16], dtype=float)],
304-
[[0., 0.53980074, 0.826991, 1.02758204], [0, 0, 0, 1, 1]],
305-
[False, True]
306-
)
307-
], ids=[
308-
'norm_is_None',
309-
'LogNorm_and_LinearNorm',
310-
'PowerNorm_clip_None_and_True',
311-
'SymLogNorm_and_PowerNorm_clip_in_call'
312-
]
313-
)
314-
def test_BivariateNorm(norm1, norm2, values, expected, clip):
315-
norm = mcolors.BivariateNorm(norm1=norm1, norm2=norm2)
316-
ans1, ans2 = norm(values=values, clip=clip)
317-
assert_array_almost_equal(ans1, expected[0])
318-
assert_array_almost_equal(ans2, expected[1])
319-
320275

321276
@image_comparison(baseline_images=['levels_and_colors'],
322277
extensions=['png'])

0 commit comments

Comments
 (0)