Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit018c5ef

Browse files
authored
Merge pull request#24912 from anntzer/cw
Remove contour warning for "no-valid-levels".
2 parentscf1b601 +fd6604d commit018c5ef

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed
Lines 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

Lines 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-
ifnotself.filled:
1142-
inside= (self.levels>self.zmin)& (self.levels<self.zmax)
1143-
levels_in=self.levels[inside]
1144-
iflen(levels_in)==0:
1145-
self.levels= [self.zmin]
1146-
_api.warn_external(
1147-
"No contour levels were found within the data range.")
1148-
11491140
ifself.filledandlen(self.levels)<2:
11501141
raiseValueError("Filled contours require at least 2 levels.")
1151-
11521142
iflen(self.levels)>1andnp.min(np.diff(self.levels))<=0.0:
11531143
raiseValueError("Contour levels must be increasing")
11541144

‎lib/matplotlib/tests/test_contour.py

Lines 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-
deftest_contour_empty_levels():
66-
67-
x=np.arange(9)
68-
z=np.random.random((9,9))
69-
65+
deftest_contour_no_valid_levels():
7066
fig,ax=plt.subplots()
71-
withpytest.warns(UserWarning)asrecord:
72-
ax.contour(x,x,z,levels=[])
73-
assertlen(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
deftest_contour_Nlevels():
@@ -84,33 +85,6 @@ def test_contour_Nlevels():
8485
assert (cs1.levels==cs2.levels).all()
8586

8687

87-
deftest_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-
withpytest.warns(UserWarning)asrecord:
98-
cs=ax.contour(x,x,z,levels=[1.])
99-
ax.clabel(cs,fmt=fmt)
100-
assertlen(record)==1
101-
102-
103-
deftest_contour_uniform_z():
104-
105-
x=np.arange(9)
106-
z=np.ones((9,9))
107-
108-
fig,ax=plt.subplots()
109-
withpytest.warns(UserWarning)asrecord:
110-
ax.contour(x,x,z)
111-
assertlen(record)==1
112-
113-
11488
@image_comparison(['contour_manual_labels'],remove_text=True,style='mpl20')
11589
deftest_contour_manual_labels():
11690
x,y=np.meshgrid(np.arange(0,10),np.arange(0,10))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp