Often, when creating a plot I would like several plots with the data. It's possible to return the name of one file as output, using results: file, but what about returning several?

For reference, I'd like a solution that works for any language, but I'm working with Python at the moment.

1 Answer 1


This is a solution for python, using noweb syntax. It saves all open matplotlib figures, but the idea can be extended easily. First off, make sure noweb is enabled in settings. Then, define a function which returns a list of filenames.

#+name: plt-save
#+begin_src python :exports results :results verbatim
idx = get_fignums()
files = []

for i in idx:
    files.append('{0}_{1}.png'.format(path, i))
    savefig(numbered[-1], bbox_inches='tight')
return "\n".join(["[[file:{0}]]".format(f) for f in files])

Then, in the block where the figures are to be saved, define a variable path, call <<plt-save>>, and set the results to verbatim.

#+begin_src python :results verbatim

# Do processing here#

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.