Plotting CDF of a pandas series in python

后端 未结 7 1155
情话喂你
情话喂你 2020-12-23 09:25

Is there a way to do this? I cannot seem an easy way to interface pandas series with plotting a CDF.

7条回答
  •  误落风尘
    2020-12-23 09:42

    I believe the functionality you're looking for is in the hist method of a Series object which wraps the hist() function in matplotlib

    Here's the relevant documentation

    In [10]: import matplotlib.pyplot as plt
    
    In [11]: plt.hist?
    ...
    Plot a histogram.
    
    Compute and draw the histogram of *x*. The return value is a
    tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
    [*patches0*, *patches1*,...]) if the input contains multiple
    data.
    ...
    cumulative : boolean, optional, default : True
        If `True`, then a histogram is computed where each bin gives the
        counts in that bin plus all bins for smaller values. The last bin
        gives the total number of datapoints.  If `normed` is also `True`
        then the histogram is normalized such that the last bin equals 1.
        If `cumulative` evaluates to less than 0 (e.g., -1), the direction
        of accumulation is reversed.  In this case, if `normed` is also
        `True`, then the histogram is normalized such that the first bin
        equals 1.
    
    ...
    

    For example

    In [12]: import pandas as pd
    
    In [13]: import numpy as np
    
    In [14]: ser = pd.Series(np.random.normal(size=1000))
    
    In [15]: ser.hist(cumulative=True, density=1, bins=100)
    Out[15]: 
    
    In [16]: plt.show()
    

提交回复
热议问题