Last active
March 15, 2016 03:18
-
-
Save BaxterEaves/73cfb94ea5c31fe285ad to your computer and use it in GitHub Desktop.
P-P plot of the empirical CDFs of values in two lists.
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
import numpy as np | |
import matplotlib.pyplot as plt | |
def pp_plot(f, p, nbins, ax=None): | |
""" P-P plot of the empirical CDFs of values in two lists, f and p. """ | |
if ax is None: | |
ax = plt.gca() | |
uniqe_vals_f = list(set(f)) | |
uniqe_vals_p = list(set(p)) | |
combine = uniqe_vals_f | |
combine.extend(uniqe_vals_p) | |
combine = list(set(combine)) | |
if len(uniqe_vals_f) > nbins: | |
bins = nbins | |
else: | |
bins = sorted(combine) | |
bins.append(bins[-1]+bins[-1]-bins[-2]) | |
ff, edges = np.histogram(f, bins=bins, density=True) | |
fp, _ = np.histogram(p, bins=edges, density=True) | |
Ff = np.cumsum(ff*(edges[1:]-edges[:-1])) | |
Fp = np.cumsum(fp*(edges[1:]-edges[:-1])) | |
plt.plot([0, 1], [0, 1], c='dodgerblue', lw=2, alpha=.8) | |
plt.plot(Ff, Fp, c='black', lw=2, alpha=.9) | |
plt.xlim([0, 1]) | |
plt.ylim([0, 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment