Is it possible to create plot (matplotlib) with a href in its title?

Viewed 205

I wanted to make this link interactive, unfortunately it doesn't display any html content. Is there any way to make this title as a href?

    from matplotlib import pyplot as plt
    import numpy as np

    fig, axs1 = plt.subplots(1)
    import numpy as np
    x = np.linspace(0, 2 * np.pi, 400)
    y = np.sin(x ** 2)
    axs1.plot(x)
    axs1.set_title("<a href=vk.com>vk.com</a>")
    plt.show()

href

2 Answers

You can set text labels as hyperlink. But you can't set title as hyperlink.

For the first one, see a stack-overflow answer.

You can use the following method to write the title as a text instead of using set_title

import numpy as np
from matplotlib import pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats("svg")

fig, axs1 = plt.subplots(figsize=(6, 4))
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
axs1.plot(x, y)
text = axs1.annotate("vk.com", xy=(0.5,1), xytext=(0.5,0.96), 
                     xycoords='figure fraction',
                     verticalalignment='top',
                     url='vk.com', fontsize=16)
plt.show()
Related