Created
October 7, 2020 20:50
-
-
Save jzhou77/fd46d521e6321bd34f4fc9c01e32d32c to your computer and use it in GitHub Desktop.
CDF Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'recovery-duration.txt' file content: | |
Duration | |
0.127489 | |
0.134138 | |
0.151415 | |
0.180696 | |
0.196397 | |
0.212269 | |
0.243426 | |
0.263445 | |
0.272921 | |
0.274783 | |
0.308237 | |
Script to generate CDF plot: | |
from pandas import read_csv, to_datetime | |
import matplotlib.pyplot as plt | |
from pandas.plotting import register_matplotlib_converters | |
df = read_csv('recovery-duration.txt') | |
stats_df = df.groupby('Duration')['Duration'].agg('count').pipe(pd.DataFrame)\ | |
.rename(columns = {'Duration': 'frequency'}) | |
stats_df['pdf'] = stats_df['frequency'] / sum(stats_df['frequency']) | |
# CDF | |
stats_df['cdf'] = stats_df['pdf'].cumsum() | |
stats_df = stats_df.reset_index() | |
# stats_df | |
fig = plt.figure() | |
# stats_df.plot(x='Duration', y=['cdf'], grid = True) | |
plt.plot('Duration', 'cdf', data=stats_df, linewidth=2, ) | |
plt.xlabel('Recovery Duration (s)') | |
plt.ylabel('CDF') | |
plt.grid(True) | |
plt.ylim(0.0, 1.0) | |
plt.xlim(0, 10) | |
SMALL_SIZE = 10 | |
MEDIUM_SIZE = 12 | |
BIGGER_SIZE = 14 | |
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels | |
plt.rc('xtick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels | |
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels | |
fig.savefig('recovery-duration.pdf') | |
fig.savefig('recovery-duration.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment