Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01a4e9f

Browse filesBrowse files
authored
Merge pull request #24963 from meeseeksmachine/auto-backport-of-pr-24912-on-v3.7.x
Backport PR #24912 on branch v3.7.x (Remove contour warning for "no-valid-levels".)
2 parents df9dfda + 9dd1223 commit 01a4e9f
Copy full SHA for 01a4e9f

File tree

Expand file treeCollapse file tree

3 files changed

+13
-45
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+13
-45
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``contour`` no longer warns if no contour lines are drawn.
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
This can occur if the user explicitly passes a ``levels`` array with no values
4+
between ``z.min()`` and ``z.max()``; or if ``z`` has the same value everywhere.

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,18 +1137,8 @@ def _process_contour_level_args(self, args, z_dtype):
11371137
self.levels = self._autolev(levels_arg)
11381138
else:
11391139
self.levels = np.asarray(levels_arg, np.float64)
1140-
1141-
if not self.filled:
1142-
inside = (self.levels > self.zmin) & (self.levels < self.zmax)
1143-
levels_in = self.levels[inside]
1144-
if len(levels_in) == 0:
1145-
self.levels = [self.zmin]
1146-
_api.warn_external(
1147-
"No contour levels were found within the data range.")
1148-
11491140
if self.filled and len(self.levels) < 2:
11501141
raise ValueError("Filled contours require at least 2 levels.")
1151-
11521142
if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
11531143
raise ValueError("Contour levels must be increasing")
11541144

‎lib/matplotlib/tests/test_contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_contour.py
+9-35Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ def test_contour_shape_error(args, message):
6262
ax.contour(*args)
6363

6464

65-
def test_contour_empty_levels():
66-
67-
x = np.arange(9)
68-
z = np.random.random((9, 9))
69-
65+
def test_contour_no_valid_levels():
7066
fig, ax = plt.subplots()
71-
with pytest.warns(UserWarning) as record:
72-
ax.contour(x, x, z, levels=[])
73-
assert len(record) == 1
67+
# no warning for empty levels.
68+
ax.contour(np.random.rand(9, 9), levels=[])
69+
# no warning if levels is given and is not within the range of z.
70+
cs = ax.contour(np.arange(81).reshape((9, 9)), levels=[100])
71+
# ... and if fmt is given.
72+
ax.clabel(cs, fmt={100: '%1.2f'})
73+
# no warning if z is uniform.
74+
ax.contour(np.ones((9, 9)))
7475

7576

7677
def test_contour_Nlevels():
@@ -84,33 +85,6 @@ def test_contour_Nlevels():
8485
assert (cs1.levels == cs2.levels).all()
8586

8687

87-
def test_contour_badlevel_fmt():
88-
# Test edge case from https://github.com/matplotlib/matplotlib/issues/9742
89-
# User supplied fmt for each level as a dictionary, but Matplotlib changed
90-
# the level to the minimum data value because no contours possible.
91-
# This was fixed in https://github.com/matplotlib/matplotlib/pull/9743
92-
x = np.arange(9)
93-
z = np.zeros((9, 9))
94-
95-
fig, ax = plt.subplots()
96-
fmt = {1.: '%1.2f'}
97-
with pytest.warns(UserWarning) as record:
98-
cs = ax.contour(x, x, z, levels=[1.])
99-
ax.clabel(cs, fmt=fmt)
100-
assert len(record) == 1
101-
102-
103-
def test_contour_uniform_z():
104-
105-
x = np.arange(9)
106-
z = np.ones((9, 9))
107-
108-
fig, ax = plt.subplots()
109-
with pytest.warns(UserWarning) as record:
110-
ax.contour(x, x, z)
111-
assert len(record) == 1
112-
113-
11488
@image_comparison(['contour_manual_labels'], remove_text=True, style='mpl20')
11589
def test_contour_manual_labels():
11690
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.