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

Commit 2ccd085

Browse filesBrowse files
tacaswelldstansby
authored andcommitted
Merge pull request matplotlib#15140 from dstansby/mask-fmt
FIX: ScalarFormatter formatting of masked values
1 parent 169a9f7 commit 2ccd085
Copy full SHA for 2ccd085

File tree

Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+15Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+2Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.