```#+TITLE: Simple Plots

One of my most frequent tasks is plotting x-y plots.

#+BEGIN_SRC emacs-lisp
(require 'ob-ipython)
#+END_SRC

#+BEGIN_SRC ipython :session mplt
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
#+END_SRC

#+RESULTS:

#+BEGIN_SRC ipython :session mplt
import os
import re
from functools import reduce

path = os.path.join(os.getcwd(), "simpleplot.org")
contents = None
with open(path) as simpleplot:
contents = re.sub(r'[^a-zA-Z]', '', contents.lower())

def group(value, element):
if not value[1] or value[1][-1] != element:
value[0].append(1)
value[1].append(str(element))
else:
value[0][-1] += 1
return value

counts, characters = reduce(group, sorted(contents), ([], []))
counts, characters = zip(
*sorted(zip(counts, characters), key=lambda x: x[0]))
#+END_SRC

#+RESULTS:

#+BEGIN_SRC ipython :session mplt :file ../../static/images/alphabets.png
ticks = range(len(counts))
plt.figure(figsize=(5, 7))
plt.barh(ticks, counts, tick_label=characters)
plt.show()
#+END_SRC

#+RESULTS:
file:../../static/images/alphabets.png

* Testing
file:../../static/images/alphabets.png
```