def plot_pdf_log2(x, nbins=10, **kwargs):
'''
Adds a log-log PDF plot to the current axes. The PDF is binned with
logarithmic binning of base 2.
Arguments
---------
x : array_like
The data to plot
nbins : integer
The number of bins to take
Additional keyword arguments are passed to `matplotlib.pyplot.loglog`.
'''
x = np.asarray(x)
exp_max = np.ceil(np.log2(x.max()))
bins = np.logspace(0, exp_max, exp_max + 1, base=2)
ax = plt.gca()
hist, _ = np.histogram(x, bins=bins)
binsize = np.diff(np.asfarray(bins))
hist = hist / binsize
ax.loglog(bins[1:], hist, 'ow', **kwargs)
return ax
评论列表
文章目录