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

Skip to content

Commit 813e41a

Browse files
kidkoder432QuLogic
andauthored
Boxplot fix median line extending past box boundaries (#26462)
Closes #19409. - Set the default capstyles (solid and dashed) for median and mean lines in boxplots to "butt". I also modieifed the behaviror for setting the capstyle for median lines to obey the user's preference instead of overriding it. - The boxplot PDFs were using the wrong capstyle, so I modified the references to use the butt captyle. - Fixed a small typo in `bxp()` - Added a new test for the median line (from PR #23335) Co-authored-by: Elliott Sales de Andrade <[email protected]>
1 parent db533bf commit 813e41a

37 files changed

+21
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4095,7 +4095,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
40954095
40964096
capwidths : float or array-like, default: None
40974097
Either a scalar or a vector and sets the width of each cap.
4098-
The default is ``0.5*(with of the box)``, see *widths*.
4098+
The default is ``0.5*(width of the box)``, see *widths*.
40994099
41004100
vert : bool, default: True
41014101
If `True` (default), makes the boxes vertical.
@@ -4147,6 +4147,17 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
41474147
--------
41484148
.. plot:: gallery/statistics/bxp.py
41494149
"""
4150+
# Clamp median line to edge of box by default.
4151+
medianprops = {
4152+
"solid_capstyle": "butt",
4153+
"dash_capstyle": "butt",
4154+
**(medianprops or {}),
4155+
}
4156+
meanprops = {
4157+
"solid_capstyle": "butt",
4158+
"dash_capstyle": "butt",
4159+
**(meanprops or {}),
4160+
}
41504161

41514162
# lists of artists to be output
41524163
whiskers = []
Binary file not shown.
Binary file not shown.
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,6 +3223,15 @@ def test_bxp_customwhisker():
32233223
whiskerprops=dict(linestyle='-', color='m', lw=3)))
32243224

32253225

3226+
@check_figures_equal()
3227+
def test_boxplot_median_bound_by_box(fig_test, fig_ref):
3228+
data = np.arange(3)
3229+
medianprops_test = {"linewidth": 12}
3230+
medianprops_ref = {**medianprops_test, "solid_capstyle": "butt"}
3231+
fig_test.subplots().boxplot(data, medianprops=medianprops_test)
3232+
fig_ref.subplots().boxplot(data, medianprops=medianprops_ref)
3233+
3234+
32263235
@image_comparison(['bxp_withnotch.png'],
32273236
remove_text=True,
32283237
savefig_kwarg={'dpi': 40},

0 commit comments

Comments
 (0)