summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-03-15 15:21:22 -0600
committerGitHub <noreply@github.com>2018-03-15 15:21:22 -0600
commitfc26f49cca51207596862ad2df986d03ec56b19b (patch)
tree9d5039f9154cbac39f1964adab95795e5e1bd515
parent83c669997a53ac5734327abd99da1813718503fc (diff)
parente3ff50194c0633113ae543700d83ebb165c8d06b (diff)
downloadpython-numpy-fc26f49cca51207596862ad2df986d03ec56b19b.tar.gz
python-numpy-fc26f49cca51207596862ad2df986d03ec56b19b.tar.bz2
python-numpy-fc26f49cca51207596862ad2df986d03ec56b19b.zip
Merge pull request #10750 from eric-wieser/percentile-graph
DOC: Add graph showing different behaviors of np.percentile
-rw-r--r--numpy/lib/function_base.py27
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):