Skip to content

Fix ScalarFormatter formatting of masked values #15140

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2019
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