0

When exporting images to multiple formats (I have tried html and pdf), the export works but the image is not displayed. This is only a problem when the image is in a #+RESULTS: block. Moving the image outside the results block fixes the problem. For example:

#+begin_src jupyter-python :results file :file ~/image.jpg
    import numpy as np
    import matplotlib.pyplot as plt

    a = np.array([1, 2, 3, 4, 5])
    b = np.array([1, 2, 3, 4, 5])

    plt.plot(a, b)
    plt.show()
#+end_src
#+RESULTS:
:RESULTS:
#+attr_org: :width 547
[[file:~/image.jpg]]
:END:

will not display an image.

The problem occurs when using pandoc or org-export.

2 Answers 2

0

Assuming your source block has successfully produced the image file[1], there are two problems: you need to add an :exports results header to your code block so that the results can be exported and you need to make sure that drawers can be exported (they are not by default I believe[3]). So the following should work[2]:

# enable exports of drawers
#+OPTIONS: d:t

* Foo
#+begin_src jupyter-python :exports results :results file :file ~/image.jpg
...
#+end_src

#+RESULTS:
:RESULTS:
#+attr_org: :width 547
[[file:~/image.jpg]]
:END:

See the Org manual for more details: Export settings for the #+OPTIONS setting and Exporting code blocks for the :exports header (note the s BTW - spelling it :export is a common mistake).

BTW, it's not clear why your result is in a drawer: presumably you have a :results drawer header either on your code block or as a property, but you have not shown that in your question. If that is the case, you can get rid of that header instead of enabling drawer export with the #+OPTION above.


Footnotes:

[1] The code block seems incomplete to me - e.g. don't you need a savefig somewhere? - but I don't have a jupyter-python evaluator so I can't test that.

[2] It works for me: I had to use my own code block and image, but that should not make any difference.

[3] I was wondering why the OP's answer of :exports both would work for him, so I looked a bit more closely and found out I was wrong: the default value of org-export-with-drawers is (not "LOGBOOK") - IOW, all drawers except the LOGBOOK drawer are exported. So the d:t option is not needed; only :exports results on the code block is needed for the results to be exported (:exports both exports both the code and the results).

0

The solution is to add

:exports both

to the header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.