3 ms·
How do you plot graphs with org? I've been trying to use it for that purpose but I can't wrap my head around how to do it without some tikz incantation I don't
by taink 4y ago
How do you plot graphs with org? I've been trying to use it for that purpose but I can't wrap my head around how to do it without some tikz incantation I don't really understand. I've seen gnuplot mentioned here and there but the setup seems pretty involved.
I'm looking for a way to plot simple numeric data signals in time series, which are pretty trivial in jupyter notebooks.
- V1ndaar 4y agoWell, personally as I write almost all my code in Nim and am the developer of ggplotnim [0], I simply write a source code snippet with some short Nim code, generate a plot and dump the filename into the Org file. If I had more time and wanted something more convenient and magical, I would probably write a elisp function that takes X Y (Z) columns and generates a plot from those using a simple Nim program in the back that receives the data, generates the plot and returns it somehow. Haven't given this much thought though. [0]: https://github.com/Vindaar/ggplotnim https://github.com/Vindaar/ggplotnim
- hoosieree 4y agoI mostly use matplotlib+seaborn in a python code block, and tell matplotlib to write pdf output. Then I'll include the pdf with a link. Here's a sketch: # first run this code block: #+begin_src python # some code to generate a plot at images/plot.pdf #+end_src # then put the image where you want it: #+CAPTION: Some plot or other #+NAME: fig:asdfhjkl #+ATTR_LATEX: :width 0.7\textwidth [[file:./images/plot.pdf]] You can put some incantation on the top of your .org file to make it run all the code blocks before exporting, but I usually just run them manually if I need to make a change to a figure. Here's a full example from one of my papers. You can see I made quite a few revisions with all the commented-out lines. Note the :results none :exports none arguments to the org-babel code block, which makes the code itself invisible in the resulting paper. #+begin_src python :results none :exports none import matplotlib.pyplot as plt import seaborn as sns def get_loss(filename): loss = [] with open(filename) as f: for line in f: loss.append(float(line.split(' = ')[-1])) return loss data = {} # data['NLP (P=0.1)'] = get_loss( '../sample-programs/loss-epochs-nlp-0.1-30.txt') # data['NLP (P=0.2)'] = get_loss( '../sample-programs/loss-epochs-nlp-0.2-30.txt') # data['NLP (P=0.4)'] = get_loss( '../sample-programs/loss-epochs-nlp-0.4-30.txt') # data['NLP (P=0.8)'] = get_loss( '../sample-programs/loss-epochs-nlp-0.8-30.txt') data['NLP (P=0.1)'] = get_loss( '../sample-programs/loss-epochs-both-0.1-30.txt') data['NLP (P=0.2)'] = get_loss( '../sample-programs/loss-epochs-both-0.2-30.txt') data['NLP (P=0.4)'] = get_loss( '../sample-programs/loss-epochs-both-0.4-30.txt') # data['NLP (P=0.8)'] = get_loss( '../sample-programs/loss-epochs-both-0.8-30.txt') data['Plain'] = get_loss( '../sample-programs/loss-epochs-30.txt') sns.lineplot(data=data, palette='deep') # TODO add plots for combined Plain+NLP at other probabilities plt.xlabel('Epoch') plt.ylabel('Loss') plt.legend() filename = 'images/loss-plot.pdf' plt.savefig(filename) return filename #+end_src #+CAPTION: Training loss for data augmentation #+LABEL: fig:loss #+ATTR_LATEX: :width 0.5\textwidth #+RESULTS: fig:loss [[file:./images/loss-plot.pdf]]