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

Commitfe4b36b

Browse files
committed
Fix format_cursor_data with nans.
Without this fix, hovering the mouse over a nan pixel in an imshow()would result in `Warning: converting a masked element to nan.` and then`ValueError: cannot convert float NaN to integer`. Fix that.The format_cursor_data test doesn't explicitly check the return valueof get_cursor_data anymore because np.ma.masked is returned for naninputs (this is expected from the general approach for handling invaliddata); checking that format_cursor_data gives the right string issufficient.
1 parenta35f108 commitfe4b36b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

‎lib/matplotlib/artist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,8 @@ def format_cursor_data(self, data):
12731273
# from Artist first and from ScalarMappable second, so
12741274
# Artist.format_cursor_data would always have precedence over
12751275
# ScalarMappable.format_cursor_data.
1276+
ifnp.ma.getmask(data):
1277+
return"[]"
12761278
n=self.cmap.N
12771279
# Midpoints of neighboring color intervals.
12781280
neighbors=self.norm.inverse(

‎lib/matplotlib/tests/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ def test_cursor_data():
340340
"data, text", [
341341
([[10001,10000]],"[10001.000]"),
342342
([[.123,.987]],"[0.123]"),
343+
([[np.nan,1,2]],"[]"),
343344
])
344345
deftest_format_cursor_data(data,text):
345346
frommatplotlib.backend_basesimportMouseEvent
@@ -349,7 +350,6 @@ def test_format_cursor_data(data, text):
349350

350351
xdisp,ydisp=ax.transData.transform([0,0])
351352
event=MouseEvent('motion_notify_event',fig.canvas,xdisp,ydisp)
352-
assertim.get_cursor_data(event)==data[0][0]
353353
assertim.format_cursor_data(im.get_cursor_data(event))==text
354354

355355

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp