Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7278d2

Browse files
phobsonpelson
authored andcommitted
BUG: fixed weird case where boxplot whiskers went inside box
1 parent 50508af commit c7278d2

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

doc/users/whats_new.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ using Inkscape for example, while preserving their intended position. For
8484
`svg` please note that you'll have to disable the default text-to-path
8585
conversion (`mpl.rc('svg', fonttype='none')`).
8686

87+
More robust boxplots
88+
--------------------
89+
Paul Hobson provided a fix to the :func:`~matplotlib.pyplot.boxplot`
90+
method that prevent whiskers from being drawn inside the box for
91+
oddly distributed data sets.
92+
8793
Triangular grid interpolation
8894
-----------------------------
8995
Geoffroy Billotey and Ian Thomas added classes to perform interpolation within

lib/matplotlib/axes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6027,17 +6027,19 @@ def computeConfInterval(data, med, iq, bootstrap):
60276027
iq = q3 - q1
60286028
hi_val = q3 + whis * iq
60296029
wisk_hi = np.compress(d <= hi_val, d)
6030-
if len(wisk_hi) == 0:
6030+
if len(wisk_hi) == 0 or np.max(wisk_hi) < q3:
60316031
wisk_hi = q3
60326032
else:
60336033
wisk_hi = max(wisk_hi)
6034+
60346035
# get low extreme
60356036
lo_val = q1 - whis * iq
60366037
wisk_lo = np.compress(d >= lo_val, d)
6037-
if len(wisk_lo) == 0:
6038+
if len(wisk_lo) == 0 or np.min(wisk_lo) > q1:
60386039
wisk_lo = q1
60396040
else:
60406041
wisk_lo = min(wisk_lo)
6042+
60416043
# get fliers - if we are showing them
60426044
flier_hi = []
60436045
flier_lo = []

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,18 @@ def test_boxplot():
964964
conf_intervals=[None, (-1.0, 3.5)], notch=1)
965965
ax.set_ylim((-30, 30))
966966

967+
@image_comparison(baseline_images=['boxplot_no_inverted_whisker'],
968+
remove_text=True, extensions=['png'],
969+
savefig_kwarg={'dpi': 40})
970+
def test_boxplot_no_weird_whisker():
971+
x = np.array([3, 9000, 150, 88, 350, 200000, 1400, 960],
972+
dtype=np.float64)
973+
ax1 = plt.axes()
974+
ax1.boxplot(x)
975+
ax1.set_yscale('log')
976+
ax1.yaxis.grid(False, which='minor')
977+
ax1.xaxis.grid(False)
978+
967979
@image_comparison(baseline_images=['errorbar_basic',
968980
'errorbar_mixed'])
969981
def test_errorbar():

0 commit comments

Comments
 (0)