3

I am new to Python and figured out that I can plot color maps the following way:

    import matplotlib.pyplot as plt
    #some image generating code
    
    plot = plt.imshow(image)
    plot.set_cmap(cmap)
    plot.set_interpolation(interpolation_method)
    plt.show()

Where image is an 2-dimensional numpy array in my case. As result I get a beautiful colormap (could not post an image of it since I am new to this platform). Link to my color map: http://s7.directupload.net/images/131017/t9aczkmq.png)

enter image description here

My Question

Is there a way to display the current value of a position/pixel in the upper colormap on mouse hovering? I need to display the actual value (within the array that has been plotted) not the color value.

Additional Question

Is there also a way to add a slicer to the output in order to change the cuts of the color map dynamically (similar to a FITS viewer).

Probably I just need the right modules, but I could not find any fitting my needs yet. Thanks in advance!

4
  • 1
    I think this neat little matplotlib tool could be adapted for your mouse-hovering purposes. As is it's designed to show the x-y coordinates, but it could be changed to output your array values instead. Commented Oct 17, 2013 at 9:41
  • @Brionius Thanks for your hint, I realized that the tool you mentioned is designed for 2 dimensional plots. It will be difficult for me to adapt it to the 3 dimensional case (color maps), since its an complete different class that I have to deal with called AxesImage generated by plt.imshow(image). Still hoping for more replies or help with the code adaption of the mentioned tool. Commented Oct 17, 2013 at 10:31
  • 1
    @user2889722 - The "full" tool that Brionius mentioned ( github.com/joferkington/mpldatacursor#working-with-images ) does more-or-less exactly what you want. Also, for your second question, are you asking for something like this? stackoverflow.com/a/5613068/325565 (Sorry to plug my own answer on both of these, but hopefully it helps, regardless.) Commented Oct 17, 2013 at 11:42
  • 1
    stackoverflow.com/questions/14754931/… and matplotlib.org/examples/api/image_zcoord.html @JoeKington I see no problem with you plugging your own answers or tool Commented Oct 17, 2013 at 16:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.