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

Commitc51aeef

Browse files
Fixed bug in find_nearest_contour; Added test
1 parent6c3412b commitc51aeef

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎lib/matplotlib/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
13711371
# Nonetheless, improvements could probably be made.
13721372

13731373
ifindicesisNone:
1374-
indices=range(len(self.levels))
1374+
indices=range(len(self.layers))
13751375

13761376
d2min=np.inf
13771377
conmin=None

‎lib/matplotlib/tests/test_contour.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,28 @@ def test_contour_line_start_on_corner_edge():
470470
cbar.add_lines(lines)
471471

472472

473+
deftest_find_nearest_contour():
474+
xy=np.indices((10,10))
475+
img=np.exp(-np.pi*(np.sum((xy-5)**2,0)/5.**2))
476+
cs=plt.contourf(img,10)
477+
478+
nearest_contour=cs.find_nearest_contour(1,1,pixel=False)
479+
expected_nearest= (0,0,1,1.0,0.0,1.0)
480+
assert_array_almost_equal(nearest_contour,expected_nearest)
481+
482+
nearest_contour=cs.find_nearest_contour(8,1,pixel=False)
483+
expected_nearest= (0,0,16,7.550173,1.587542,0.547551)
484+
assert_array_almost_equal(nearest_contour,expected_nearest)
485+
486+
nearest_contour=cs.find_nearest_contour(2,5,pixel=False)
487+
expected_nearest= (2,0,35,1.884384,4.976664,0.013911)
488+
assert_array_almost_equal(nearest_contour,expected_nearest)
489+
490+
nearest_contour=cs.find_nearest_contour(2,5,indices=(5,7),pixel=False)
491+
expected_nearest= (5,0,16,2.628202,5.0,0.394638)
492+
assert_array_almost_equal(nearest_contour,expected_nearest)
493+
494+
473495
@mpl.style.context("default")
474496
deftest_contour_autolabel_beyond_powerlimits():
475497
ax=plt.figure().add_subplot()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp