diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index d99323d0608e..bbc489502262 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1042,8 +1042,9 @@ def format_cursor_data(self, data): data[0] except (TypeError, IndexError): data = [data] - return ', '.join('{:0.3g}'.format(item) for item in data if - isinstance(item, (np.floating, np.integer, int, float))) + data_str = ', '.join('{:0.3g}'.format(item) for item in data if + isinstance(item, (np.floating, np.integer, int, float))) + return "[" + data_str + "]" @property def mouseover(self): diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index fc92f6dd1869..ddd4e6d3b0ba 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2860,7 +2860,9 @@ def mouse_move(self, event): if a is not event.inaxes.patch: data = a.get_cursor_data(event) if data is not None: - s += ' [%s]' % a.format_cursor_data(data) + data_str = a.format_cursor_data(data) + if data_str is not None: + s = s + ' ' + data_str if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 3fcb3cb5c6a1..9c9249da8fb8 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -344,7 +344,9 @@ def send_message(self, event): if a is not event.inaxes.patch: data = a.get_cursor_data(event) if data is not None: - s += ' [%s]' % a.format_cursor_data(data) + data_str = a.format_cursor_data(data) + if data_str is not None: + s = s + ' ' + data_str message = s self.toolmanager.message_event(message, self)