Support for Scalar Image Cursor Display? · Issue #3984 · matplotlib/matplotlib · GitHub
Skip to content

Support for Scalar Image Cursor Display? #3984

Description

@blink1073

How would everyone feel about the following change? It will show the z value of a scalar image in the cursor if available (similar to what Matlab does). If there is no image or the image is RGB, it will revert to the previous behaviour.

--- a/lib/matplotlib/axes/_base.py
+++ b/lib/matplotlib/axes/_base.py
@@ -2971,7 +2971,12 @@ class _AxesBase(martist.Artist):
             ys = '???'
         else:
             ys = self.format_ydata(y)
-        return 'x=%s y=%s' % (xs, ys)
+        try:
+            z = self.images[0].get_array()[int(y + 0.5), int(x + 0.5)]
+            zs = self.format_xdata(z)
+            return 'x=%s y=%s z=%s' % (xs, ys, zs)
+        except:
+            return 'x=%s y=%s' % (xs, ys)

     def minorticks_on(self):
         'Add autoscaling minor ticks to the axes.'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions