[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] ob-python: support header argument `:results file graphics'
From: |
Ihor Radchenko |
Subject: |
Re: [PATCH] ob-python: support header argument `:results file graphics' |
Date: |
Mon, 03 Jul 2023 09:28:48 +0000 |
Liu Hui <liuhui1610@gmail.com> writes:
> This patch adds graphics output support for ob-python via matplotlib.
> Specifically, it allows to use header argument `:results file
> graphics' as follows:
>
> #+begin_src python :file "test.png" :results graphics file
> import matplotlib.pyplot as plt
> plt.plot([1,2,3,4,5])
> #+end_src
This might be a useful feature, but it will break the existing
conventions, if used as in the patch. Currently, the above combination
of :file and :results is treated as the following:
‘graphics’
When used along with ‘file’ type, the result is a link to the file
specified in ‘:file’ header argument. However, unlike plain ‘file’
type, code block output is not written to the disk. The block is
expected to generate the file by its side-effects only, as in the
following example:
#+begin_src shell :results file link :file "org-mode-unicorn.svg"
wget -c "https://orgmode.org/resources/img/org-mode-unicorn.svg"
#+end_src
#+RESULTS:
[[file:org-mode-unicorn.svg]]
If ‘:file’ header argument is omitted, interpret source block
result as the file path.
> +try:
> + import matplotlib.pyplot
> + if len(matplotlib.pyplot.get_fignums()) > 0:
> + matplotlib.pyplot.gcf().savefig('%s')
> + else:
> + raise RuntimeError('No figure is found. You need to use matplotlib\
> + functions, such as plot and imshow, to produce the graphics.')
> +except ModuleNotFoundError:
> + raise RuntimeError('ob-python depends on matplotlib for saving graphics')
What if the user wants to use, for example, pyplot instead of
matplotlib?
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
- [PATCH] ob-python: support header argument `:results file graphics', Liu Hui, 2023/07/03
- Re: [PATCH] ob-python: support header argument `:results file graphics',
Ihor Radchenko <=
- Re: [PATCH] ob-python: support header argument `:results file graphics', Liu Hui, 2023/07/03
- Re: [PATCH] ob-python: support header argument `:results file graphics', Ihor Radchenko, 2023/07/03
- Re: [PATCH] ob-python: support header argument `:results file graphics', Liu Hui, 2023/07/03
- Re: [PATCH] ob-python: support header argument `:results file graphics', Ihor Radchenko, 2023/07/04
- Re: [PATCH] ob-python: support header argument `:results file graphics', Jack Kamm, 2023/07/05
- Re: [PATCH] ob-python: support header argument `:results file graphics', Ihor Radchenko, 2023/07/05
- Re: [PATCH] ob-python: support header argument `:results file graphics', Jack Kamm, 2023/07/05
- Re: [PATCH] ob-python: support header argument `:results file graphics', Ihor Radchenko, 2023/07/07
- Re: [PATCH] ob-python: support header argument `:results file graphics', Jack Kamm, 2023/07/08
- Re: [PATCH] ob-python: support header argument `:results file graphics', Ihor Radchenko, 2023/07/09