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

Skip to content

Commit 90468b0

Browse files
committed
scatter() should not rescale if norm is given
1 parent 24caa1b commit 90468b0

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4471,10 +4471,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44714471
collection.set_cmap(cmap)
44724472
collection.set_norm(norm)
44734473

4474-
if vmin is not None or vmax is not None:
4475-
collection.set_clim(vmin, vmax)
4476-
else:
4477-
collection.autoscale_None()
4474+
if norm is None:
4475+
if vmin is not None or vmax is not None:
4476+
collection.set_clim(vmin, vmax)
4477+
else:
4478+
collection.autoscale_None()
44784479

44794480
# Classic mode only:
44804481
# ensure there are margins to allow for the
@@ -5652,10 +5653,11 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
56525653
if im.get_clip_path() is None:
56535654
# image does not already have clipping set, clip to axes patch
56545655
im.set_clip_path(self.patch)
5655-
if vmin is not None or vmax is not None:
5656-
im.set_clim(vmin, vmax)
5657-
else:
5658-
im.autoscale_None()
5656+
if norm is None:
5657+
if vmin is not None or vmax is not None:
5658+
im.set_clim(vmin, vmax)
5659+
else:
5660+
im.autoscale_None()
56595661
im.set_url(url)
56605662

56615663
# update ax.dataLim, and, if autoscaling, set viewLim

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,16 @@ def test_imshow_clip():
10041004
ax.imshow(r, clip_path=clip_path)
10051005

10061006

1007+
@check_figures_equal(extensions=["png"])
1008+
def test_impshow_norm_vminvmax(self, fig_test, fig_ref):
1009+
"""Parameters vmin, vmax should be ignored if norm is given."""
1010+
a = [[1, 2], [3, 4]]
1011+
ax = fig_ref.subplots()
1012+
ax.imshow(a, norm=mcolors.Normalize(-10, 10))
1013+
ax = fig_test.subplots()
1014+
ax.imshow(a, norm=mcolors.Normalize(-10, 10), vmin=0, vmax=5)
1015+
1016+
10071017
@image_comparison(['polycollection_joinstyle'], remove_text=True)
10081018
def test_polycollection_joinstyle():
10091019
# Bug #2890979 reported by Matthew West
@@ -1973,6 +1983,15 @@ def test_scatter_no_invalid_color(self, fig_test, fig_ref):
19731983
ax = fig_ref.subplots()
19741984
ax.scatter([0, 2], [0, 2], c=[1, 2], s=[1, 3], cmap=cmap)
19751985

1986+
@check_figures_equal(extensions=["png"])
1987+
def test_scatter_norm_vminvmax(self, fig_test, fig_ref):
1988+
"""Parameters vmin, vmax should be ignored if norm is given."""
1989+
x = [1, 2, 3]
1990+
ax = fig_ref.subplots()
1991+
ax.scatter(x, x, c=x, norm=mcolors.Normalize(-10, 10))
1992+
ax = fig_test.subplots()
1993+
ax.scatter(x, x, c=x, norm=mcolors.Normalize(-10, 10), vmin=0, vmax=5)
1994+
19761995
@check_figures_equal(extensions=["png"])
19771996
def test_scatter_single_point(self, fig_test, fig_ref):
19781997
ax = fig_test.subplots()

0 commit comments

Comments
 (0)