8000 Merge pull request #15187 from dstansby/15140-backport · matplotlib/matplotlib@c615fd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c615fd4

Browse files
authored
Merge pull request #15187 from dstansby/15140-backport
Backport PR #15140 on branch v3.1.x
2 parents 1191549 + 2ccd085 commit c615fd4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,3 +989,18 @@ def test_deprecation():
989989
with pytest.warns(MatplotlibDeprecationWarning):
990990
# Enough arguments to pass "shape" positionally.
991991
obj.imshow(data, *[None] * 10)
992+
993+
994+
def test_image_cursor_formatting():
995+
fig, ax = plt.subplots()
996+
# Create a dummy image to be able to call format_cursor_data
997+
im = ax.imshow(np.zeros((4, 4)))
998+
999+
data = np.ma.masked_array([0], mask=[True])
1000+
assert im.format_cursor_data(data) == '[]'
1001+
1002+
data = np.ma.masked_array([0], mask=[False])
1003+
assert im.format_cursor_data(data) == '[0]'
1004+
1005+
data = np.nan
1006+
assert im.format_cursor_data(data) == '[nan]'

lib/matplotlib/ticker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ def format_data_short(self, value):
629629
"""
630630
if self._useLocale:
631631
return locale.format_string('%-12g', (value,))
632+
elif isinstance(value, np.ma.MaskedArray) and value.mask:
633+
return ''
632634
else:
633635
return '%-12g' % value
634636

0 commit comments

Comments
 (0)
0