Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I see that matplotlib's artist has the ability to embed hyperlinks into graph objects as seen in the
documentation
and briefly mentioned
here
.
I would like to attempt to embed hyperlinks into the points of a scatter plot but have some general confusion about how to integrate or access the artist in my plot.
The Stackoverflow examples linked above lead me to believe that this is easier if I plot blank text elements over the scatter plot, and the text elements contain the hyperlinks.
There is very little information beyond the two resources I shared, any additional insight would be greatly appreciated.
Here is a way to automatically open a web browser and go to a specific URL when clicking on the points of a scatter plot. Parts of the code below come from
here
.
Here is the code:
import matplotlib.pyplot as plt
import webbrowser
#set_matplotlib_formats("svg")
class custom_objects_to_plot:
def __init__(self, x, y, name):
self.x = x
self.y = y
self.name = name
a = custom_objects_to_plot(10, 20, "a")
b = custom_objects_to_plot(30, 5, "b")
c = custom_objects_to_plot(40, 30, "c")
d = custom_objects_to_plot(120, 10, "d")
def on_pick(event):
webbrowser.open('https://stackoverflow.com')
fig, ax = plt.subplots()
for obj in [a, b, c, d]:
artist = ax.plot(obj.x, obj.y, 'ro', picker=5)[0]
artist.obj = obj
fig.canvas.callbacks.connect('pick_event', on_pick)
plt.show()
And the output looks like that:
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.