Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursor location and pixel value in a Jupyter notebook inline image

I am using Python 2.7.x with a Jupyter Notebook, matplotlib and %pylab backend with the inline flag %pylab inline to print images below active cells. I would like to be able to move my cursor over an image and know it's location and pixel value An example could be: (x,y,val) = (123,285,230) but I am not particular about any of the specifics of this example.

like image 646
DanGoodrick Avatar asked Apr 13 '17 15:04

DanGoodrick


People also ask

What is the %Matplotlib inline?

You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.

What does %% capture do in Jupyter?

Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.

What does %Matplotlib do in Jupyter?

In the IPython notebook, you also have the option of embedding graphics directly in the notebook, with two possible options: %matplotlib notebook will lead to interactive plots embedded within the notebook. %matplotlib inline will lead to static images of your plot embedded in the notebook.


1 Answers

The %matplotlib inline backend displays the plot outputs as png images. It may be possible to write some JavaScript for the Jupyter notebook to obtain the color and pixel on mouse over an image in the cell output.

However it may be much easier to just use the %matplotlib notebook backend, which keeps the matplotlib figure alive when plotting it to the output and therefore the usual built-in mouseover functionality is readily available.

enter image description here

Note the picker in the lower right corner of the image, which displays x,y and the value of the current pixel.

like image 103
ImportanceOfBeingErnest Avatar answered Oct 06 '22 20:10

ImportanceOfBeingErnest