Latex Citation in matplotlib Legend

Check out tikzplotlib (a project of mine). You can use it to save matplotlib figures as TikZ/Pgfplots which retains a lot of informations and which are very easily editable. Adding a BibTeX citation as a legend is no problem at all.


This can be done using the matplotlib pgf backend for python. The python file for generating the graph is as follows:

import numpy as np
import matplotlib as mpl
mpl.use('pgf')
import matplotlib.pyplot as plt

x = np.linspace(0., 1., num=100)
y = x**2

plt.plot(x, y, label=r'Data \cite{<key>}')
plt.legend(loc=0)
plt.savefig('fig.pgf')

The pgf file can then be utilized in a latex paper as such:

\documentclass[letterpaper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{pgf}

\begin{document}

  \begin{figure}
    \centering
    \input{fig.pgf}
    \caption{Test Figure}
  \end{figure}

\end{document}

Whenever the latex file is compiled, the citation in the legend will be updated automatically.