njszym
njszym

Reputation: 41

How to use pgf backend to include hyperlink in matplotlib pdf plot?

I wish to include a hyperlink in a matplotlib plot, which I can output as a pdf (to later be inserted into a LaTeX document).

I know this kind of question has been asked, but the solutions which I've seen only seem to give rise to some error. I'm currently attempting to use the pgf backend, and my code is as below:

import matplotlib
matplotlib.use('pgf')
import matplotlib.pyplot as plt

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
matplotlib.rcParams['pgf.preamble'] = [r'\usepackage{hyperref}', ]

x = (1,2,3,4)
y = (1,4,9,16)

plt.figure()
plt.plot(x,y,'bo')
plt.title(r"\href{http://www.google.com}{Test Link}",color='blue')
plt.savefig('Test.pdf')
plt.close()

However, I keep getting the following error:

    matplotlib.backends.backend_pgf.LatexError: 
LaTeX returned an error, probably missing font or error in preamble

Not sure why this is, any help would be greatly appreciated.

Upvotes: 1

Views: 613

Answers (0)

Related Questions