【发布时间】:2019-11-20 10:25:05
【问题描述】:
我试图绘制本福德定律
#+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
运行并得到结果
我想要的结果是
创建直方图
#+begin_src ipython :session alinbx :results drawer
plt.hist(results,bins=9)
plt.axis([1, 10, 1])
#+end_src
但是得到了结果
然后我花了几个小时阅读:
- 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?
在完成这项简单的任务之前,我只是发布一个应该是 matplotlib 超级大师的人。
您能提供任何提示吗?
【问题讨论】:
-
你想做条形图,而不是直方图matplotlib.org/3.1.1/gallery/ticks_and_spines/…
标签: python matplotlib