matplotlib.pyplot.hist(
x, bins=10, range=None, normed=False,
weights=None, cumulative=False, bottom=None,
histtype=u'bar', align=u'mid', orientation=u'vertical',
rwidth=None, log=False, color=None, label=None, stacked=False,
hold=None, **kwargs)
(density : bool, optionalIf True, the first element of the return tuple will be the counts normalized to form a probability density, i.e., the area (or integral) under the histogram will sum to 1. This is achieved by dividing the count by the number of observations times the bin width and not dividing by the total number of observations. If stacked is also True, the sum of the histograms is normalized to 1.Default is None for both normed and density. If either is set, then that value will be used. If neither are set, then the args will be treated as False.If both density and normed are set an error is raised.)
返回值:
例子2:
随机生成一些数字:daily_maxes
daily_maxes.shape (10000,)
# probs:y值
# hungers:x值
probs, hungers, _ = hist(daily_maxes, normed=True, bins=100)
scipy.optimize.curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
check_finite=True, bounds=(-inf, inf), method=None, **kwargs)
用途:Use non-linear least squares to fit a function, f
, to data.Assumes ydata = f(xdata, *params) + eps
参数函数f
拟合一个给定的数据,返回拟合数据时的参数值。
返回:
# 定义一个函数,含有两个超参数,loc和scale,求这两个参数。
def gumbel_pdf(prob, loc, scale):
z = (prob - loc) / scale
return exp(-z - exp(-z)) / scale
# 传入函数,x值,y值
(loc, scale), _ = curve_fit(gumbel_pdf, hungers[:-1], probs)
curve_fit 官网解释:http://lagrange.univ-lyon1.fr/docs/scipy/0.17.1/generated/scipy.optimize.curve_fit.html
直方图:
例子:https://www.cnblogs.com/python-life/articles/6084059.html
官网解释:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html
直方图的缺点,密度图的优点:https://towardsdatascience.com/histograms-and-density-plots-in-python-f6bda88f5ac0
另外:
关于可视化的python手册:https://serialmentor.com/dataviz/histograms-density-plots.html