The context
Consider the following Emacs configuration
$ cat ~/.emacs.d/init.el
(org-babel-do-load-languages 'org-babel-load-languages
'((python . t)))
$
and the following Org mode file
$ cat ~/Experiments/main.org
#+begin_src python :tangle main.py :results file :file 1.png
from matplotlib import pyplot
x = [1, 2, 3]
y = [1, 4, 9]
pyplot.plot(x, y)
pyplot.savefig('1.png')
#+end_src
$
If I tangle the Python code block (i.e. execute org-babel-tangle
), execute the Python script (i.e. execute python main.py
in a shell) and obtain the hash of the resulting image I get
$ pwd
/home/myusername/Experiments
$ python main.py
$ sha512sum 1.png && du -h 1.png
084ffd63ec53665c21fc3eaba5f5ec3622d4d27a97f89cb67e3b436ca8093467272bbc239fd0e60dde27f5207ee33392f5b83b9eca1427efe7523450d92a6a8c 1.png
20K 1.png
I can open 1.png
with firefox
and mpv
without any problems.
If I execute the code block in Emacs by pressing C-c C-c
(i.e. execute org-babel-execute-src-block
) while the cursor is in the #+BEGIN_SRC
block, I get the following
$ sha512sum 1.png && du -h 1.png
e39d05b72f25767869d44391919434896bb055772d7969f74472032b03bc18418911f3b0e6dd47ff8f3b2323728225286c3cb36914d28dc7db40bdd786159c0a 1.png
4.0K 1.png
Note that the size of 1.png
is significantly lower than the size shown above.
Additional context
In addition to that, if I try to open the image with mpv
, I get the following error
$ mpv 1.png
(+) Video --vid=1 (png 1.000fps)
[ffmpeg/video] png: Invalid PNG signature 0x00000000.
Error while decoding frame!
(Paused) V: 00:00:01 / 00:00:01 (100%)
[ffmpeg/video] png: Invalid PNG signature 0x00000000.
Error while decoding frame!
(Paused) V: 00:00:01 / 00:00:01 (100%)
An error is also shown when I try to open the image in firefox
(see image below)
The error is not present in both firefox
and mpv
when producing the image 1.png
by executing the script in a shell.
The question
- Why is the file
1.png
obtained after executingorg-babel-execute-src-block
different than the one produced by tangling the#+BEGIN_SRC
block and executingpython main.py
in a shell? - Why does the resulting file
1.png
contain errors?