This a python copy of the popular and highly upvoted Create pdf with tooltips in R .
Simple question: Is there a way to plot a graph from python in a pdf file and include tooltips?
You can use the matplotlib pgf backend to do that. Then you can use different packages at the preamble. In this case I am using the pdfcomment.
This is a very simple example, but I think you can go from here!
import matplotlib as mpl
mpl.use("pgf")
pgf_with_pdflatex = {
"pgf.texsystem": "pdflatex",
"pgf.preamble": [
r"\usepackage[author={me}]{pdfcomment}",
]
}
mpl.rcParams.update(pgf_with_pdflatex)
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
for i in range(5):
plt.text(i,i,r"\pdftooltip{o}{(%d,%d)}"%(i,i))
plt.savefig("tooltips.pdf")
There is a slight misplacement of the character "o", but that can be fixed with few tweaks. It is also much simpler than the R case.
PS: The tooltips can only be visualised with Acrobat Reader.
Hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With