FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remove contour warning for "no-valid-levels". by anntzer · Pull Request #24912 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/behavior/24912-AL.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``contour`` no longer warns if no contour lines are drawn.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This can occur if the user explicitly passes a ``levels`` array with no values
between ``z.min()`` and ``z.max()``; or if ``z`` has the same value everywhere.
10 changes: 0 additions & 10 deletions lib/matplotlib/contour.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1137,18 +1137,8 @@ def _process_contour_level_args(self, args, z_dtype):
self.levels = self._autolev(levels_arg)
else:
self.levels = np.asarray(levels_arg, np.float64)

if not self.filled:
inside = (self.levels > self.zmin) & (self.levels < self.zmax)
levels_in = self.levels[inside]
if len(levels_in) == 0:
self.levels = [self.zmin]
_api.warn_external(
"No contour levels were found within the data range.")

if self.filled and len(self.levels) < 2:
raise ValueError("Filled contours require at least 2 levels.")

if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
raise ValueError("Contour levels must be increasing")

Expand Down
44 changes: 9 additions & 35 deletions lib/matplotlib/tests/test_contour.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ def test_contour_shape_error(args, message):
ax.contour(*args)


def test_contour_empty_levels():

x = np.arange(9)
z = np.random.random((9, 9))

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


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


def test_contour_badlevel_fmt():
# Test edge case from https://github.com/matplotlib/matplotlib/issues/9742
# User supplied fmt for each level as a dictionary, but Matplotlib changed
# the level to the minimum data value because no contours possible.
# This was fixed in https://github.com/matplotlib/matplotlib/pull/9743
x = np.arange(9)
z = np.zeros((9, 9))

fig, ax = plt.subplots()
fmt = {1.: '%1.2f'}
with pytest.warns(UserWarning) as record:
cs = ax.contour(x, x, z, levels=[1.])
ax.clabel(cs, fmt=fmt)
assert len(record) == 1


def test_contour_uniform_z():

x = np.arange(9)
z = np.ones((9, 9))

fig, ax = plt.subplots()
with pytest.warns(UserWarning) as record:
ax.contour(x, x, z)
assert len(record) == 1


@image_comparison(['contour_manual_labels'], remove_text=True, style='mpl20')
def test_contour_manual_labels():
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))
Expand Down

Back | FazBrowse Home | New Git URL