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

Skip to content

Commit 9285372

Browse files
committed
fix failing commits
1 parent 96af3d3 commit 9285372

File tree

5 files changed

+22
-118
lines changed

5 files changed

+22
-118
lines changed

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)
@@ -5151,6 +5138,11 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51515138
51525139
"""
51535140

5141+
temp = np.asarray(X)
5142+
if temp.ndim == 3 and isinstance(norm, mcolors.BivariateNorm):
5143+
temp = norm(temp)
5144+
X = cmap(temp, alpha=self.get_alpha(), bytes=True)
5145+
51545146
if not self._hold:
51555147
self.cla()
51565148

@@ -5164,21 +5156,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51645156
aspect = rcParams['image.aspect']
51655157
self.set_aspect(aspect)
51665158

5167-
temp = np.asarray(X)
5168-
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
5169-
isinstance(cmap, mcolors.BivariateColormap))
5170-
if (temp.ndim == 3 and isBivari):
5171-
if cmap is None:
5172-
cmap = mcolors.BivariateColormap()
5173-
if norm is None:
5174-
norm = mcolors.BivariateNorm()
5175-
temp = norm(temp)
5176-
temp[0] = temp[0] * (cmap.N-1)
5177-
temp[1] = temp[1] * (cmap.N-1)
5178-
temp = temp.astype(int)
5179-
X = temp[0] + cmap.N * temp[1]
5180-
norm = mcolors.NoNorm()
5181-
51825159
im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
51835160
filternorm=filternorm, filterrad=filterrad,
51845161
resample=resample, **kwargs)
@@ -5219,10 +5196,10 @@ def _pcolorargs(funcname, *args, **kw):
52195196
allmatch = kw.pop("allmatch", False)
52205197
norm = kw.pop("norm", None)
52215198
cmap = kw.pop("cmap", None)
5199+
alpha = kw.pop("alpha", 1)
52225200

52235201
if len(args) == 1:
52245202
C = np.asanyarray(args[0])
5225-
52265203
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
52275204
isinstance(cmap, mcolors.BivariateColormap))
52285205
if (C.ndim == 3 and isBivari):
@@ -5231,12 +5208,6 @@ def _pcolorargs(funcname, *args, **kw):
52315208
if norm is None:
52325209
norm = mcolors.BivariateNorm()
52335210
C = norm(C)
5234-
C[0] = C[0] * (cmap.N-1)
5235-
C[1] = C[1] * (cmap.N-1)
5236-
C = C.astype(int)
5237-
C = C[0] + cmap.N * C[1]
5238-
C = np.array(C)
5239-
52405211
numRows, numCols = C.shape
52415212
if allmatch:
52425213
X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
@@ -5256,11 +5227,6 @@ def _pcolorargs(funcname, *args, **kw):
52565227
if norm is None:
52575228
norm = mcolors.BivariateNorm()
52585229
C = norm(C)
5259-
C[0] = C[0] * (cmap.N-1)
5260-
C[1] = C[1] * (cmap.N-1)
5261-
C = C.astype(int)
5262-
C = C[0] + cmap.N * C[1]
5263-
C = np.array(C)
52645230
numRows, numCols = C.shape
52655231
else:
52665232
raise TypeError(
@@ -5809,19 +5775,11 @@ def pcolorfast(self, *args, **kwargs):
58095775
isBivari = (isinstance(norm, mcolors.BivariateNorm) or
58105776
isinstance(cmap, mcolors.BivariateColormap))
58115777
if (C.ndim == 3 and isBivari):
5812-
if cmap is None:
5813-
cmap = mcolors.BivariateColormap()
5814-
if norm is None:
5815-
norm = mcolors.BivariateNorm()
58165778
C = norm(C)
5817-
C[0] = C[0] * (cmap.N-1)
5818-
C[1] = C[1] * (cmap.N-1)
5819-
C = C.astype(int)
5820-
C = C[0] + cmap.N * C[1]
5821-
C = np.array(C)
5822-
norm = mcolors.NoNorm()
5823-
5824-
nr, nc = C.shape
5779+
nr, nc = C.shape
5780+
C = cmap(C, alpha=alpha, bytes=True)
5781+
else:
5782+
nr, nc = C.shape
58255783
if len(args) == 1:
58265784
style = "image"
58275785
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
@@ -1417,22 +1417,13 @@ def __call__(self, values, clip=None):
14171417
if clip is None:
14181418
clip = [self.norm1.clip, self.norm2.clip]
14191419

1420-
return np.asarray([self.norm1(values[0], clip=clip[0]),
1421-
self.norm2(values[1], clip=clip[1])])
1420+
temp = np.asarray([self.norm1(values[0], clip=clip[0]),
1421+
self.norm2(values[1], clip=clip[1])])
14221422

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

14371428
def autoscale(self, A):
14381429
"""

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)