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!

6
  • 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 bokeh.pydata.org/en/latest/docs/user_guide/tools.html Commented Dec 28, 2016 at 5: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? Commented Dec 28, 2016 at 5: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! Commented Dec 28, 2016 at 5:39
  • 1
    @AquilesPáez I haven't embedded it into a GUI but have used it with Jupyter and it works fine. Commented Dec 28, 2016 at 5:47
  • 1
    I think the answer is here: link. Commented Jan 21, 2019 at 4:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.