plotting.py 文件源码

python
阅读 54 收藏 0 点赞 0 评论 0

项目:knowledge_linker 作者: glciampaglia 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号