diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-03-15 15:21:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-15 15:21:22 -0600 |
commit | fc26f49cca51207596862ad2df986d03ec56b19b (patch) | |
tree | 9d5039f9154cbac39f1964adab95795e5e1bd515 /numpy/lib/function_base.py | |
parent | 83c669997a53ac5734327abd99da1813718503fc (diff) | |
parent | e3ff50194c0633113ae543700d83ebb165c8d06b (diff) | |
download | numpy-fc26f49cca51207596862ad2df986d03ec56b19b.tar.gz |
Merge pull request #10750 from eric-wieser/percentile-graph
DOC: Add graph showing different behaviors of np.percentile
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 07b845e2b..bff3798ca 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3478,6 +3478,33 @@ def percentile(a, q, axis=None, out=None, array([ 7., 2.]) >>> assert not np.all(a == b) + The different types of interpolation can be visualized graphically: + + ..plot:: + import matplotlib.pyplot as plt + + a = np.arange(4) + p = np.linspace(0, 100, 6001) + ax = plt.gca() + lines = [ + ('linear', None) + ('higher', '--') + ('lower', '--') + ('nearest', '-.') + ('midpoint', '-.') + ] + for interpolation, style in lines: + ax.plot( + p, np.percentile(a, p, interpolation=interpolation), + label=interpolation, linestyle=style) + ax.set( + title='Interpolation methods for list: ' + str(a), + xlabel='Percentile', + ylabel='List item returned', + yticks=a) + ax.legend() + plt.show() + """ q = np.true_divide(q, 100.0) # handles the asarray for us too if not _quantile_is_valid(q): |