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

Fix format_cursor_data with nans.#21145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 1 commit intomatplotlib:masterfromanntzer:fcdn
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletionslib/matplotlib/artist.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1274,11 +1274,18 @@ def format_cursor_data(self, data):
# Artist.format_cursor_data would always have precedence over
# ScalarMappable.format_cursor_data.
n = self.cmap.N
# Midpoints of neighboring color intervals.
neighbors = self.norm.inverse(
(int(self.norm(data) * n) + np.array([0, 1])) / n)
delta = abs(neighbors - data).max()
return "[{:-#.{}g}]".format(data, cbook._g_sig_digits(data, delta))
if np.ma.getmask(data):
return "[]"
normed = self.norm(data)
if np.isfinite(normed):
# Midpoints of neighboring color intervals.
neighbors = self.norm.inverse(
(int(self.norm(data) * n) + np.array([0, 1])) / n)
delta = abs(neighbors - data).max()
g_sig_digits = cbook._g_sig_digits(data, delta)
else:
g_sig_digits = 3 # Consistent with default below.
return "[{:-#.{}g}]".format(data, g_sig_digits)
else:
try:
data[0]
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/tests/test_image.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ def test_cursor_data():
"data, text", [
([[10001, 10000]], "[10001.000]"),
([[.123, .987]], "[0.123]"),
([[np.nan, 1, 2]], "[]"),
])
def test_format_cursor_data(data, text):
from matplotlib.backend_bases import MouseEvent
Expand All@@ -349,7 +350,6 @@ def test_format_cursor_data(data, text):

xdisp, ydisp = ax.transData.transform([0, 0])
event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp)
assert im.get_cursor_data(event) == data[0][0]
assert im.format_cursor_data(im.get_cursor_data(event)) == text


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp