So I am trying to create a Data Science workflow using org-mode source-blocks. Basically, I need to emulate the jupyter notebook functionality where you create a plot and it shows the figure. Now, following this link, you can do this:
#+begin_src python :results file import matplotlib, numpy matplotlib.use('Agg') import matplotlib.pyplot as plt fig=plt.figure(figsize=(4,2)) x=numpy.linspace(-15,15) plt.plot(numpy.sin(x)/x) fig.tight_layout() plt.savefig('images/python-matplot-fig.png') return 'images/python-matplot-fig.png' # return filename to org-mode #+end_src
The problem with this is that, you have to save the figure manually and then you have to return the path to the figure (Because org is wrapping that code in a function).
That is super awkward to me, because I don't want to be saving the figure manually nor have that return statement at the end, because I want to export these org files to my blog using orig-publish, and that return statement is not valid code outside of the org source blocks code context. I then tried to do this:
#+begin_src python :file example.png :dir images/ :results file import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set() # Enable Seaborn theme random_points = np.random.randint(0, 10, (100, 2)) plt.scatter(random_points[:, 0], random_points[:, 1]) plt.show() #+end_src #+RESULTS: [[file:images/example.png]]
But the problem is that, it does not save any figure at the images/example.png path. What I would want to do would be that org-mode would save that figure on the path I specified in the header, and then allow me to visualize it in the results.
How could I achieve this? Thank you!