<p dir="auto"><a href="https://sourceforge.net/tracker/?func=detail&amp;aid=3151034&amp;group_id=80706&amp;atid=560720" rel="nofollow">Original report at SourceForge, opened Tue Jan  4 04:52:13 2011</a></p>
<p dir="auto">If the boxplot is called with a small number of discrete, not unique values it shows a different median value than the median command. I consider this a bug.</p>
<p dir="auto">How to reproduce:</p>
<h1 dir="auto">example data</h1>
<p dir="auto">d = array([ 13.,   9.,  16.,   8.,   7.,  14.,  15.,   5.,  10.,  16.,   8., 15.,  14.,  19.,  10.,  10.], dtype=float32)<br>
q1, med, q3 = mlab.prctile(d,[25,50,75]) # axes.py line 5005 axes.py (0.99.3 Rev 8345)<br>
med_default = median(d) # for comparison<br>
print((med,med_default)) # med = 13.0  med_default = 11.5</p>
<p dir="auto">In the example I took the line in axes.py where the median value is computed and compare to a median directly computed. In my opinion the boxplot should use the median function to determine the median such that the same value is reported. I think the reason is in the different handling of equal values of prctile and median.</p>
<p dir="auto">Anyway: Here is how to fix it:<br>
Replace line 5005 with:<br>
q1, q3 = mlab.prctile(d,[25,75])<br>
And add a new line directly after it (new 5006):<br>
med = np.median(d)</p>
<h3 dir="auto">SourceForge Comments</h3>
<h4 dir="auto">On Thu Jan 13 04:42:32 2011, jmdb wrote:</h4>
<p dir="auto">And to add another point: matlab reports 8.5 for q1.</p>
<h4 dir="auto">On Thu Jan 13 04:37:33 2011, jmdb wrote:</h4>
<p dir="auto">In addition: if one also computes:<br>
from scipy import stats<br>
stats.scoreatpercentile(d,25)</p>
<p dir="auto">results in 8.75 while q1 from the example (which should be the same) is 9.0</p>
<p dir="auto">I think either the mlab.prctle function should be fixed or be replaced by the function from the stats package.</p>
<h4 dir="auto">On Tue Jan  4 05:03:55 2011, jmdb wrote:</h4>
<p dir="auto">Seems like this is also discussed here: <a href="http://permalink.gmane.org/gmane.comp.python.matplotlib.general/25835" rel="nofollow">http://permalink.gmane.org/gmane.comp.python.matplotlib.general/25835</a></p>
<p dir="auto">I can add that the median function agrees with f.ex. matlab while the prctile function gives different results.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">Triangulation misses data points when data is far from the origin (eg example attached is in terms of a projection coordinate system with a false origin).</p>
<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri

data=np.loadtxt('tricont.dat')
print data.shape
x=data[:,0]
y=data[:,1]
t=tri.Triangulation(x,y)
plt.triplot(t)
plt.plot(x,y,'k+')
plt.show()
x -= (x.min()+x.max())/2.0
y -= (y.min()+y.max())/2.0
t=tri.Triangulation(x,y)
plt.triplot(t)
plt.plot(x,y,'k+')
plt.show()
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">tri</span> <span class="pl-k">as</span> <span class="pl-s1">tri</span>

<span class="pl-s1">data</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">loadtxt</span>(<span class="pl-s">'tricont.dat'</span>)
<span class="pl-k">print</span> <span class="pl-s1">data</span>.<span class="pl-s1">shape</span>
<span class="pl-s1">x</span><span class="pl-c1">=</span><span class="pl-s1">data</span>[:,<span class="pl-c1">0</span>]
<span class="pl-s1">y</span><span class="pl-c1">=</span><span class="pl-s1">data</span>[:,<span class="pl-c1">1</span>]
<span class="pl-s1">t</span><span class="pl-c1">=</span><span class="pl-s1">tri</span>.<span class="pl-v">Triangulation</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">triplot</span>(<span class="pl-s1">t</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>,<span class="pl-s">'k+'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()
<span class="pl-s1">x</span> <span class="pl-c1">-=</span> (<span class="pl-s1">x</span>.<span class="pl-en">min</span>()<span class="pl-c1">+</span><span class="pl-s1">x</span>.<span class="pl-en">max</span>())<span class="pl-c1">/</span><span class="pl-c1">2.0</span>
<span class="pl-s1">y</span> <span class="pl-c1">-=</span> (<span class="pl-s1">y</span>.<span class="pl-en">min</span>()<span class="pl-c1">+</span><span class="pl-s1">y</span>.<span class="pl-en">max</span>())<span class="pl-c1">/</span><span class="pl-c1">2.0</span>
<span class="pl-s1">t</span><span class="pl-c1">=</span><span class="pl-s1">tri</span>.<span class="pl-v">Triangulation</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">triplot</span>(<span class="pl-s1">t</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>,<span class="pl-s">'k+'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto">Data in: <a href="https://github.com/matplotlib/matplotlib/files/1123260/tricont.zip">tricont.zip</a></p>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/631058/27845470-cdc94708-6183-11e7-9097-927026fb78c8.png"><img src="https://user-images.githubusercontent.com/631058/27845470-cdc94708-6183-11e7-9097-927026fb78c8.png" alt="tricont" style="max-width: 100%;"></a></p>
<p dir="auto">Triangulation misses most data points</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/631058/27845572-8ff7d132-6184-11e7-9c9f-ec50d489f5c6.png"><img src="https://user-images.githubusercontent.com/631058/27845572-8ff7d132-6184-11e7-9c9f-ec50d489f5c6.png" alt="tricont2" style="max-width: 100%;"></a></p>
<p dir="auto">Triangulation includes all data points</p>


<p dir="auto"><strong>Matplotlib version</strong></p>
<p dir="auto">Seen in version 1.5.1 and higher.<br>
Not seen in version 1.3.1</p>

<ul dir="auto">
<li>Operating System: Ubuntu 16.04</li>
<li>Matplotlib Version: 1.5.1</li>
<li>Python Version: 2.7.12</li>
<li>Jupyter Version (if applicable):</li>
<li>Other Libraries:</li>
</ul>


<p dir="auto">Installed from Ubuntu package repository</p>