end*_*ith 5 matplotlib histogram
Matplotlibhist
说“计算并绘制 x 的直方图”。我想在不先计算任何东西的情况下制作一个情节。我有 bin 宽度(不相等)和每个 bin 中的总量,我想绘制频率-数量直方图。
例如,随着数据
cm Frequency
65-75 2
75-80 7
80-90 21
90-105 15
105-110 12
Run Code Online (Sandbox Code Playgroud)
它应该是这样的情节:
http://www.gcsemathstutor.com/histograms.php
其中块的面积代表每个类别的频率。
与大卫·茨威克(David Zwicker)从事相同的工作:
import numpy as np
import matplotlib.pyplot as plt
freqs = np.array([2, 7, 21, 15, 12])
bins = np.array([65, 75, 80, 90, 105, 110])
widths = bins[1:] - bins[:-1]
heights = freqs.astype(np.float)/widths
plt.fill_between(bins.repeat(2)[1:-1], heights.repeat(2), facecolor='steelblue')
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4628 次 |
最近记录: |