Impossible to hide cursor data / imshow() / Toolbar message / format_cursor_data()

Hello,

Please consider the figure produced by "im = imshow(scipy.misc.face())". The
message in the Toolbar reflects the position of the cursor and displays for
example:

"x=843.9 y=384.7 [91, 102, 88]"

I changed the method "im.axes.format_coord()" in order to show specific
information in the Toolbar message, and this works fine.

However, the value of the cursor data, i.e. the string " [91, 102, 88]" in the
example above, is still printed after my home-made coordinate information.

PROBLEM: I don't want this information to be displayed.

NOT A SOLUTION: I overrode the method "im.format_cursor_data()" so that it
returns either "" or 'None'. However, in both cases, the brackets are still
displayed, showing either " []" or " [None]", which I find unsatisfactory.

It seems that the brackets are hardcoded in
"backend_bases.NavigationToolbar2.mouse_move()".

Is there a clean way to get rid of the cursor data and the brackets?

If not, I suggest the patch below. Does it make sense? The effect is simply
that if "im.format_cursor_data()" returns 'None', no cursor data will be
appended to the coordinate information.

Best regards,

Olivier

"""
--- backend_bases.py 2017-12-10 04:59:43.000000000 +0100
+++ temp/backend_bases.py 2018-03-23 22:09:10.611351451 +0100
@@ -2898,7 +2898,9 @@
                      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))
"""

I think this is reasonable. Can you make a Pull Request with this change?

···

On Fri, Mar 23, 2018 at 5:28 PM, Olivier via Matplotlib-users < matplotlib-users at python.org> wrote:

Hello,

Please consider the figure produced by "im = imshow(scipy.misc.face())".
The message in the Toolbar reflects the position of the cursor and displays
for example:

"x=843.9 y=384.7 [91, 102, 88]"

I changed the method "im.axes.format_coord()" in order to show specific
information in the Toolbar message, and this works fine.

However, the value of the cursor data, i.e. the string " [91, 102, 88]" in
the example above, is still printed after my home-made coordinate
information.

PROBLEM: I don't want this information to be displayed.

NOT A SOLUTION: I overrode the method "im.format_cursor_data()" so that it
returns either "" or 'None'. However, in both cases, the brackets are still
displayed, showing either " " or " [None]", which I find unsatisfactory.

It seems that the brackets are hardcoded in "backend_bases.NavigationToolb
ar2.mouse_move()".

Is there a clean way to get rid of the cursor data and the brackets?

If not, I suggest the patch below. Does it make sense? The effect is
simply that if "im.format_cursor_data()" returns 'None', no cursor data
will be appended to the coordinate information.

Best regards,

Olivier

"""
--- backend_bases.py 2017-12-10 04:59:43.000000000 +0100
+++ temp/backend_bases.py 2018-03-23 22:09:10.611351451 +0100
@@ -2898,7 +2898,9 @@
                     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))
"""

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180323/10d54b6b/attachment.html&gt;

Perhaps it might make sense to generalize this stuff even further with some
sort of format string approach with named components. So, people could
modify the format string without needing to do a massive code modification?

···

On Fri, Mar 23, 2018 at 7:50 PM, Benjamin Root <ben.v.root at gmail.com> wrote:

I think this is reasonable. Can you make a Pull Request with this change?

On Fri, Mar 23, 2018 at 5:28 PM, Olivier via Matplotlib-users < > matplotlib-users at python.org> wrote:

Hello,

Please consider the figure produced by "im = imshow(scipy.misc.face())".
The message in the Toolbar reflects the position of the cursor and displays
for example:

"x=843.9 y=384.7 [91, 102, 88]"

I changed the method "im.axes.format_coord()" in order to show specific
information in the Toolbar message, and this works fine.

However, the value of the cursor data, i.e. the string " [91, 102, 88]"
in the example above, is still printed after my home-made coordinate
information.

PROBLEM: I don't want this information to be displayed.

NOT A SOLUTION: I overrode the method "im.format_cursor_data()" so that
it returns either "" or 'None'. However, in both cases, the brackets are
still displayed, showing either " " or " [None]", which I find
unsatisfactory.

It seems that the brackets are hardcoded in "backend_bases.NavigationToolb
ar2.mouse_move()".

Is there a clean way to get rid of the cursor data and the brackets?

If not, I suggest the patch below. Does it make sense? The effect is
simply that if "im.format_cursor_data()" returns 'None', no cursor data
will be appended to the coordinate information.

Best regards,

Olivier

"""
--- backend_bases.py 2017-12-10 04:59:43.000000000 +0100
+++ temp/backend_bases.py 2018-03-23 22:09:10.611351451 +0100
@@ -2898,7 +2898,9 @@
                     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))
"""

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180323/70688723/attachment-0001.html&gt;

I think this is reasonable. Can you make a Pull Request with this change?

OK, I tried to (my first time):

···

--
Olivier