0

apple: 10.13.4

emacs: 25.3 (9)

Org-mode version 8.2.10

python3.5

As I have a bunch of harmless python blocks in an org mode file for a report, and did not want to keep pressing "y" every time that org mode asks if I want to execute the block. So I resorted to (setq org-confirm-babel-evaluate nil) . I realize that (setq org-confirm-babel-evaluate nil) may not be the best thing to do, but in some cases it can be helpful.

Anyways, this caused most of the python matplotlib plots that are made in the python blocks code to not insert in the pdf document. I am guessing that it maybe because the pdf file did not "have the time" to update with the plots through LaTeX. However, even when slowing down my code, I could only get a few of these plots to insert.

Would any one have the same issue and have a lead on how to get around that?

Example:

* making plots using matplotlib
** set-up

#+BEGIN_SRC python :session :exports results
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from os import getcwd

'current working directory: {0}'.format(getcwd())
#+END_SRC

**  Let's see if $y = sin(x)$ plot shows

#+BEGIN_SRC python :session :exports none
x = np.arange(-2*np.pi, 2*np.pi, 0.01 )
y = np.sin(x)
plt.figure(figsize=(4, 4))
plt.plot(x, y, label='sin(x)')
plt.title('sine plot')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.savefig('/Users/cybu/Desktop/test/sine.pdf')
#+END_SRC

#+BEGIN_SRC python :session :exports results :results file
'sine.pdf'
#+END_SRC


**  Let's see if $y = cos(x)$ plot shows

#+BEGIN_SRC python :session :exports none
y = np.cos(x)
plt.figure(figsize=(4, 4))
plt.plot(x, y, label='cos(x)')
plt.title('cosine plot')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.savefig('/Users/cybu/Desktop/test/cosine.pdf')
#+END_SRC

#+BEGIN_SRC python :session :exports results :results file
'cosine.pdf'
#+END_SRC
  • Please provide a minimal example for reconstruction of the problem. Also add version infos for emacs, orgmode, python, and matplotlib. – Tobias May 2 '18 at 20:23
  • added minimal example – Cy Bu May 3 '18 at 17:34
  • If that the problem occurs when you export to LaTeX and output as pdf you should write so in your question. I deleted the absolute paths in my local copy of your minimal example. My emacs-version is 25.1.50.2, my org-version is 9.1.6, and my python3 version is 3.5.2. With this setup the LaTeX export with pdf output works fine for me. All figures are included in the pdf file. – Tobias May 3 '18 at 23:29
  • I found the only hint that something could be asynchronous in matplotlib there: matplotlib.org/1.2.1/faq/howto_faq.html There one has to wait for the figure to be drawn by mpl_connect('draw_event', on_draw) in order to get the extent of the figure. – Tobias May 3 '18 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.