Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2266234

Browse filesBrowse files
authored
Merge pull request #27605 from dstansby/masked-boxplot
Ignore masked values in boxplot
2 parents 843f585 + f8b3b27 commit 2266234
Copy full SHA for 2266234

File tree

Expand file treeCollapse file tree

3 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+20
-1
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Boxplots now ignore masked data points
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
`~matplotlib.axes.Axes.boxplot` and `~matplotlib.cbook.boxplot_stats` now ignore
4+
any masked points in the input data.

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
12741274
continue
12751275

12761276
# up-convert to an array, just to be safe
1277-
x = np.asarray(x)
1277+
x = np.ma.asarray(x)
1278+
x = x.data[~x.mask].ravel()
12781279

12791280
# arithmetic mean
12801281
stats['mean'] = np.mean(x)

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,20 @@ def test_boxplot():
33883388
ax.set_ylim((-30, 30))
33893389

33903390

3391+
@check_figures_equal(extensions=["png"])
3392+
def test_boxplot_masked(fig_test, fig_ref):
3393+
# Check that masked values are ignored when plotting a boxplot
3394+
x_orig = np.linspace(-1, 1, 200)
3395+
3396+
ax = fig_test.subplots()
3397+
x = x_orig[x_orig >= 0]
3398+
ax.boxplot(x)
3399+
3400+
x = np.ma.masked_less(x_orig, 0)
3401+
ax = fig_ref.subplots()
3402+
ax.boxplot(x)
3403+
3404+
33913405
@image_comparison(['boxplot_custom_capwidths.png'],
33923406
savefig_kwarg={'dpi': 40}, style='default')
33933407
def test_boxplot_custom_capwidths():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.