Skip to content

Instantly share code, notes, and snippets.

@penghou620
Last active February 9, 2021 15:08
Show Gist options
  • Save penghou620/a5f8b08ed499bacc12440a31f0952744 to your computer and use it in GitHub Desktop.
Save penghou620/a5f8b08ed499bacc12440a31f0952744 to your computer and use it in GitHub Desktop.
Plot in Orgmode with matplotlib in python code block
#+NAME: experiments
| k | Trial 1 | Trial 2 | Trial 3 | Trial 4 | Trial 5 |
| 5 | 0.357094 | 0.332661 | 0.28434 | 0.320276 | 0.288069 |
| 10 | 0.403938 | 0.389808 | 0.36694 | 0.372952 | 0.357887 |
| 25 | 0.443313 | 0.441736 | 0.42937 | 0.425222 | 0.418354 |
| 50 | 0.471826 | 0.458904 | 0.45862 | 0.443338 | 0.445892 |
| 75 | 0.472505 | 0.473701 | 0.48072 | 0.452730 | 0.461352 |
| 100 | 0.473184 | 0.481455 | 0.49159 | 0.462386 | 0.476871 |
#+BEGIN_SRC python :results file :exports results :var data=experiments
import matplotlib.pyplot as plt
import pandas as pd
data = pd.DataFrame(data[1:], columns=data[0]).set_index('k')
data.plot(kind='bar', legend=True)
filename = "mySweetPlot.png"
plt.savefig(filename)
return(filename)
#+END_SRC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment