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

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion 4 lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,9 @@ def format_cursor_data(self, data):
delta = np.diff(
self.norm.boundaries[neigh_idx:cur_idx + 2]
).max()

elif self.norm.vmin == self.norm.vmax:
# singular norms, use delta of 10% of only value
delta = np.abs(self.norm.vmin * .1)
else:
# Midpoints of neighboring color intervals.
neighbors = self.norm.inverse(
Expand Down
4 changes: 4 additions & 0 deletions 4 lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,10 @@ def _g_sig_digits(value, delta):
it is known with an error of *delta*.
"""
if delta == 0:
if value == 0:
# if both value and delta are 0, np.spacing below returns 5e-324
# which results in rather silly results
return 3
# delta = 0 may occur when trying to format values over a tiny range;
# in that case, replace it by the distance to the closest float.
delta = abs(np.spacing(value))
Expand Down
3 changes: 2 additions & 1 deletion 3 lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def test_cursor_data_nonuniform(xy, data):
([[.123, .987]], "[0.123]"),
([[np.nan, 1, 2]], "[]"),
([[1, 1+1e-15]], "[1.0000000000000000]"),
([[-1, -1]], "[-1.0000000000000000]"),
([[-1, -1]], "[-1.0]"),
([[0, 0]], "[0.00]"),
])
def test_format_cursor_data(data, text):
from matplotlib.backend_bases import MouseEvent
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.