def plot_cdf(x, copy=True, fractional=True, **kwargs):
"""
Add a log-log CCDF plot to the current axes.
Arguments
---------
x : array_like
The data to plot
copy : boolean
copy input array in a new object before sorting it. If data is a *very*
large, the copy can avoided by passing False to this parameter.
fractional : boolean
compress the data by means of fractional ranking. This collapses the
ranks from multiple, identical observations into their midpoint, thus
producing smaller figures. Note that the resulting plot will NOT be the
exact CCDF function, but an approximation.
Additional keyword arguments are passed to `matplotlib.pyplot.loglog`.
Returns a matplotlib axes object.
"""
N = float(len(x))
if copy:
x = x.copy()
x.sort()
if fractional:
t = []
for x, chunk in groupby(enumerate(x, 1), itemgetter(1)):
xranks, _ = zip(*list(chunk))
t.append((float(x), xranks[0] + np.ptp(xranks) / 2.0))
t = np.asarray(t)
else:
t = np.c_[np.asfarray(x), np.arange(N) + 1]
if 'ax' not in kwargs:
ax = plt.gca()
else:
ax = kwargs.pop('ax')
ax.loglog(t[:, 0], (N - t[:, 1]) / N, 'ow', **kwargs)
return ax
评论列表
文章目录