3

I want to know if there are ways to display the correspondent marker (or line) values when we place the mouse cursor on such elements of a figure without clicking them, in a similar way plotly does it (some examples using scatter plots here).

What I've achieved on my own is some basic interactive plotting (adding markers to a line after clicking an element of my plot, etc). I saw this very useful package (mpldatacursor) for some of my purposes, but still is not what I'm looking for.

As you see in this example, I can choose coordinates of a line and show them but that only happens when I click such points. And I will like them to be shown without being clicked, like the plotly example.

This example is also taken from pypi.python.org/pypi/mpldatacursor

import matplotlib.pyplot as plt
import numpy as np
from mpldatacursor import datacursor

data = np.outer(range(10), range(1, 5))

fig, ax = plt.subplots()
lines = ax.plot(data)
ax.set_title('Click somewhere on a line')

datacursor(lines)

plt.show()

enter image description here

I'd be pleased to hear any suggestions you may have, take care!

Aquiles Páez
  • 503
  • 6
  • 18
  • 2
    These kinds of things require some amount of front end (javascript or something) support. Matplotlib is primarily about high quality static graphs (for papers etc). Have you tried using another library like Bokeh to do this? It can do what you're asking using the hovertool http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html – Noufal Ibrahim Dec 28 '16 at 05:16
  • @NoufalIbrahim no I haven't. I understand what you say about matplotlib's limitations, but I wanted to know if anyone else had tried something like that. Thanks for suggesting Bokeh, it looks powerful. As an additional question, have you tried embedding a Bokeh figure into a GUI? Most examples I find are with Matplotlib. Have you tried something like this? – Aquiles Páez Dec 28 '16 at 05:33
  • In general these interactive graphics are an html that with JavaScript (as Noufal Ibrahim said) make it interactive. It should not be difficult to integrate the html to the gui! – Lucas Dec 28 '16 at 05:39
  • 1
    @AquilesPáez I haven't embedded it into a GUI but have used it with Jupyter and it works fine. – Noufal Ibrahim Dec 28 '16 at 05:47
  • 1
    I think the answer is here: [link](https://stackoverflow.com/a/47166787/9422137). – anugrahandi Jan 21 '19 at 04:52
  • @AnugrahAndisetiawan that seems very very useful! Thanks for stopping by and making this suggestion :) – Aquiles Páez Jan 22 '19 at 19:33

1 Answers1

2

No, the purpose of matplotlib is not to make interactive graphics. I'm not saying it's impossible, but there are libraries for that.

Possibly useful to you bokeh

From your page:

Bokeh is a Python interactive visualization library that targets modern web browsers for presentation.

Lucas
  • 6,869
  • 5
  • 29
  • 44