Is there a way to annotate a seaborn heatmap with a clickable hyperlink in Jupyter notebook? The documentation explains clearly how to create simple annotated heatmaps. My question is, is it possible to make the annotations clickable in Jupyter?
Is there a way to annotate a seaborn heatmap with a clickable hyperlink in Jupyter notebook? The documentation explains clearly how to create simple annotated heatmaps. My question is, is it possible to make the annotations clickable in Jupyter?
In principle the answer creating a clickable hyperlink in a matplotlib figure in jupyter is given in Python matlplotlib add hyperlink to text. To apply it to a heatmap, one would need to add the texts manually. I.e. one would in that case not use seaborn to create the heatmap, but matplotlib directly.
The following creates an annotated heatmap where you can click on any number and be directed to the respective page on wolframalpha.
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats("svg")
data = np.random.randint(1,50, size=(3,3))
fig, ax = plt.subplots()
im=ax.imshow(data)
fig.colorbar(im)
for (j,i), x in np.ndenumerate(data):
url = "https://www.wolframalpha.com/input/?i={}".format(x)
ax.annotate(x, xy=(i,j), ha="center", va="center",
url=url, bbox=dict(color='w', alpha=1e-6, url=url))