[Matplotlib-users] Impossible to hide cursor data / imshow() / Toolbar message / format_cursor_data()

Olivier oc-spam65 at laposte.net
Fri Mar 23 17:28:35 EDT 2018


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))
"""



More information about the Matplotlib-users mailing list