我希望在 matplotlib 图中包含一个超链接,我可以将其输出为 pdf(稍后插入到 LaTeX 文档中)。
我知道有人问过这类问题,但我所看到的解决方案似乎只引起了一些错误。我目前正在尝试使用 pgf 后端,我的代码如下:
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()
但是,我不断收到以下错误:
matplotlib.backends.backend_pgf.LatexError:
LaTeX returned an error, probably missing font or error in preamble
不知道为什么会这样,任何帮助将不胜感激。