Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pp_plot(x, dist, line=True, ax=None):
- '''
- Function for comparing empirical data to a theoretical distribution by using a P-P plot.
- Params:
- x - empirical data
- dist - distribution object from scipy.stats; for example scipy.stats.norm(0, 1)
- line - boolean; specify if the reference line (y=x) should be drawn on the plot
- ax - specified ax for subplots, None is standalone
- '''
- if ax is None:
- ax = plt.figure().add_subplot(1, 1, 1)
- n = len(x)
- p = np.arange(1, n + 1) / n - 0.5 / n
- pp = np.sort(dist.cdf(x))
- sns.scatterplot(x=p, y=pp, color='blue', edgecolor='blue', ax=ax)
- ax.set_title('PP-plot')
- ax.set_xlabel('Theoretical Probabilities')
- ax.set_ylabel('Sample Probabilities')
- ax.margins(x=0, y=0)
- if line: plt.plot(np.linspace(0, 1), np.linspace(0, 1), 'r', lw=2)
- return ax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement