@@ -3429,6 +3429,7 @@ def extract_err(err, data):
3429
3429
3430
3430
return errorbar_container # (l0, caplines, barcols)
3431
3431
3432
+ @cbook ._rename_parameter ("3.1" , "manage_xticks" , "manage_ticks" )
3432
3433
@_preprocess_data ()
3433
3434
def boxplot (self , x , notch = None , sym = None , vert = None , whis = None ,
3434
3435
positions = None , widths = None , patch_artist = None ,
@@ -3437,7 +3438,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
3437
3438
showbox = None , showfliers = None , boxprops = None ,
3438
3439
labels = None , flierprops = None , medianprops = None ,
3439
3440
meanprops = None , capprops = None , whiskerprops = None ,
3440
- manage_xticks = True , autorange = False , zorder = None ):
3441
+ manage_ticks = True , autorange = False , zorder = None ):
3441
3442
"""
3442
3443
Make a box and whisker plot.
3443
3444
@@ -3538,8 +3539,9 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
3538
3539
Labels for each dataset. Length must be compatible with
3539
3540
dimensions of ``x``.
3540
3541
3541
- manage_xticks : bool, optional (True)
3542
- If the function should adjust the xlim and xtick locations.
3542
+ manage_ticks : bool, optional (True)
3543
+ If True, the tick locations and labels will be adjusted to match
3544
+ the boxplot positions.
3543
3545
3544
3546
autorange : bool, optional (False)
3545
3547
When `True` and the data are distributed such that the 25th and
@@ -3729,15 +3731,16 @@ def _update_dict(dictionary, rc_name, properties):
3729
3731
medianprops = medianprops , meanprops = meanprops ,
3730
3732
meanline = meanline , showfliers = showfliers ,
3731
3733
capprops = capprops , whiskerprops = whiskerprops ,
3732
- manage_xticks = manage_xticks , zorder = zorder )
3734
+ manage_ticks = manage_ticks , zorder = zorder )
3733
3735
return artists
3734
3736
3737
+ @cbook ._rename_parameter ("3.1" , "manage_xticks" , "manage_ticks" )
3735
3738
def bxp (self , bxpstats , positions = None , widths = None , vert = True ,
3736
3739
patch_artist = False , shownotches = False , showmeans = False ,
3737
3740
showcaps = True , showbox = True , showfliers = True ,
3738
3741
boxprops = None , whiskerprops = None , flierprops = None ,
3739
3742
medianprops = None , capprops = None , meanprops = None ,
3740
- meanline = False , manage_xticks = True , zorder = None ):
3743
+ meanline = False , manage_ticks = True , zorder = None ):
3741
3744
"""
3742
3745
Drawing function for box and whisker plots.
3743
3746
@@ -3841,11 +3844,12 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
3841
3844
*meanprops*. Not recommended if *shownotches* is also True.
3842
3845
Otherwise, means will be shown as points.
3843
3846
3844
- manage_xticks : bool, default = True
3845
- If the function should adjust the xlim and xtick locations.
3847
+ manage_ticks : bool, default = True
3848
+ If True, the tick locations and labels will be adjusted to match the
3849
+ boxplot positions.
3846
3850
3847
- zorder : scalar, default = None
3848
- The zorder of the resulting boxplot
3851
+ zorder : scalar, default = None
3852
+ The zorder of the resulting boxplot.
3849
3853
3850
3854
Returns
3851
3855
-------
@@ -4117,21 +4121,38 @@ def dopatch(xs, ys, **kwargs):
4117
4121
flier_x , flier_y , ** final_flierprops
4118
4122
))
4119
4123
4120
- # fix our axes/ticks up a little
4121
- if vert :
4122
- setticks = self .set_xticks
4123
- setlim = self .set_xlim
4124
- setlabels = self .set_xticklabels
4125
- else :
4126
- setticks = self .set_yticks
4127
- setlim = self .set_ylim
4128
- setlabels = self .set_yticklabels
4129
-
4130
- if manage_xticks :
4131
- newlimits = min (positions ) - 0.5 , max (positions ) + 0.5
4132
- setlim (newlimits )
4133
- setticks (positions )
4134
- setlabels (datalabels )
4124
+ if manage_ticks :
4125
+ axis_name = "x" if vert else "y"
4126
+ interval = getattr (self .dataLim , f"interval{ axis_name } " )
4127
+ axis = getattr (self , f"{ axis_name } axis" )
4128
+ positions = axis .convert_units (positions )
4129
+ # The 0.5 additional padding ensures reasonable-looking boxes
4130
+ # even when drawing a single box. We set the sticky edge to
4131
+ # prevent margins expansion, in order to match old behavior (back
4132
+ # when separate calls to boxplot() would completely reset the axis
4133
+ # limits regardless of what was drawn before). The sticky edges
4134
+ # are attached to the median lines, as they are always present.
4135
+ interval [:] = (min (interval [0 ], min (positions ) - .5 ),
4136
+ max (interval [1 ], max (positions ) + .5 ))
4137
+ for median , position in zip (medians , positions ):
4138
+ getattr (median .sticky_edges , axis_name ).extend (
4139
+ [position - .5 , position + .5 ])
4140
+ # Modified from Axis.set_ticks and Axis.set_ticklabels.
4141
+ locator = axis .get_major_locator ()
4142
+ if not isinstance (axis .get_major_locator (),
4143
+ mticker .FixedLocator ):
4144
+ locator = mticker .FixedLocator ([])
4145
+ axis .set_major_locator (locator )
4146
+ locator .locs = np .array ([* locator .locs , * positions ])
4147
+ formatter = axis .get_major_formatter ()
4148
+ if not isinstance (axis .get_major_formatter (),
4149
+ mticker .FixedFormatter ):
4150
+ formatter = mticker .FixedFormatter ([])
4151
+ axis .set_major_formatter (formatter )
4152
+ formatter .seq = [* formatter .seq , * datalabels ]
4153
+
4154
+ self .autoscale_view (
4155
+ scalex = self ._autoscaleXon , scaley = self ._autoscaleYon )
4135
4156
4136
4157
return dict (whiskers = whiskers , caps = caps , boxes = boxes ,
4137
4158
medians = medians , fliers = fliers , means = means )
0 commit comments