Skip to content
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
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,3 +1103,18 @@ def test_respects_bbox():
buf_after = io.BytesIO()
fig.savefig(buf_after, format="rgba")
assert buf_before.getvalue() != buf_after.getvalue() # Not all white.


def test_image_cursor_formatting():
fig, ax = plt.subplots()
# Create a dummy image to be able to call format_cursor_data
im = ax.imshow(np.zeros((4, 4)))

data = np.ma.masked_array([0], mask=[True])
assert im.format_cursor_data(data) == '[]'

data = np.ma.masked_array([0], mask=[False])
assert im.format_cursor_data(data) == '[0]'

data = np.nan
assert im.format_cursor_data(data) == '[nan]'
2 changes: 2 additions & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ def format_data_short(self, value):
"""
if self._useLocale:
return locale.format_string('%-12g', (value,))
elif isinstance(value, np.ma.MaskedArray) and value.mask:
return ''
else:
return '%-12g' % value

Expand Down