I try to plot Benford's law
#+begin_src ipython :session alinbx :results none
from math import log10, log
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['figure.figsize'] = (10.00, 6.18 )
def benford(n):
return log10(n+1) - log10(n)
results = [benford(i) for i in range(1, 10)]
plt.plot(list(range(1,10)), results)
#+end_src
Run and get the result
The result I want is
Create histogram
#+begin_src ipython :session alinbx :results drawer
plt.hist(results,bins=9)
plt.axis([1, 10, 1])
#+end_src
but got the results
Then I spent hours reading:
- https://matplotlib.org/3.1.1/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py
- https://matplotlib.org/3.1.1/gallery/statistics/hist.html
- How to plot a histogram using Matplotlib in Python with a list of data?
I merely release that one should be super master at matplotlib before get this easy task done.
Could you please provide any hints?