Following up on a discussion from last month [1], I am reviving my proposal from a couple years ago [2] to improve ob-python results handling. Since it's a relatively large change, I am sending it to the list for review before applying the patch. The patch changes how ob-python handles the following types of results: - Dictionaries - Numpy arrays - Pandas dataframes and series - Matplotlib figures Starting with dicts: these are no longer mangled. The current behavior (before patch) is like so: #+begin_src python return {"a": 1, "b": 2} #+end_src #+RESULTS: | a | : | 1 | b | : | 2 | But after the patch they appear like so: #+begin_src python return {"a": 1, "b": 2} #+end_src #+RESULTS: : {'a': 1, 'b': 2} Next, for numpy arrays and pandas dataframes/series: these are converted to tables, for example: #+begin_src python import pandas as pd import numpy as np return pd.DataFrame(np.array([[1,2,3],[4,5,6]]), columns=['a','b','c']) #+end_src #+RESULTS: | | a | b | c | |---+---+---+---| | 0 | 1 | 2 | 3 | | 1 | 4 | 5 | 6 | To avoid conversion, you can specify "raw", "verbatim", "scalar", or "output" in the ":results" header argument. Finally, for plots: ob-python now supports ":results graphics" header arg. The behavior depends on whether using output or value results. For output results, the current figure (pyplot.gcf) is cleared before evaluating, then the result saved. For value results, the block is expected to return a matplotlib Figure, which is saved. To set the figure size, do it from within Python. Here is an example of how to plot: #+begin_src python :results output graphics file :file boxplot.svg import matplotlib.pyplot as plt import seaborn as sns plt.figure(figsize=(5, 5)) tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips) #+end_src Compared to the original version of this patch [2], I tried to simplify and streamline things as much as possible, since this is a relatively large and complex change. For example, the handling for dict objects is much more simplistic now. And there are other miscellaneous changes to the code structure which I hope improve the clarity a bit. [1] https://list.orgmode.org/CAOQTW-N9rE7fDRM1APMO8X5LRZmJfn_ZjhT3rvaF4X+s5M_jZw@mail.gmail.com/ [2] https://list.orgmode.org/87eenpfe77.fsf@gmail.com/