Hi
I use org mode more and more to plot data using python source blocks. If
I create pngs, org mode will display these results as an inline image,
which is nice. Since I also export my org buffer via latex to pdf, it
would be nice to create pdf plots with python, so that I get vector
graphics in the pdf. This is easy to do in python's matplotlib, but once
I change to pdf output, the images don't get displayed inline in
org-mode anymore :( instead, I just get a file: link.
I had a quick look, but can't figure out how to enable this. Should be
relatively easy I would think, since emacs already can display pdfs and
right-clicking on the file: link will open a new frame with the
pdf. Is there any reason not to display them inline?
The closest I found is:
http://stackoverflow.com/questions/15407485/inline-pdf-images-in-org-mode
If it is not that easy, is there a way to run a pre-export and
post-export hook that changes my *.png files to *pdf before the export
and then changes them back to *.png after the export?
Here is a test file
#+STARTUP: inlineimages
* test
#+NAME: checkfilename
#+HEADER: :var fileout="test--checkfilename.pdf"
#+BEGIN_SRC python :session :results file
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
X = np.linspace(1, 10)
Y = np.sin(X)
ax.plot(X, Y)
fig.savefig(fileout)
plt.close(fig)
fileout
#+END_SRC
-
to create a png, just replace the .pdf in the HEADER with .png
this uses ipython and cpaste
---
; use ipython in org mode
(setq org-babel-python-command "ipython3 --no-banner --classic
--no-confirm-exit")
; use %cpaste to paste code into ipython in org mode
(defadvice org-babel-python-evaluate-session
(before org-python-use-cpaste
(session body &optional result-type result-params) activate)
"Add a %cpaste and '--' to the body, so that ipython does the right
thing."
(setq body (concat "%cpaste -q\n" body "\n--")))
---
Arun