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

Skip to content

Commit 8c9f4d4

Browse files
committed
ENH : add flag to box_plot and bxp to manage (or not) xticks
Closes #2921 - added test for managa_xtick option to boxplot - added CHANGELOG and whats_new.rst entry for manage_xticks
1 parent f93ab9b commit 8c9f4d4

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
2014-03-27 Added tests for pie ccw parameter. Removed pdf and svg images
22
from tests for pie linewidth parameter.
33

4+
2014-03-24 Added bool kwarg (manage_xticks) to boxplot to enable/disable
5+
the managemnet of the xlimits and ticks when making a boxplot.
6+
Default in True which maintains current behavior by default.
7+
48
2014-03-22 Added the keyword arguments wedgeprops and textprops to pie.
59
Users can control the wedge and text properties of the pie
610
in more detail, if they choose.

doc/users/whats_new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ kwargs. See the examples:
5656
:ref:`~examples/statistics/boxplot_demo.py` and
5757
:ref:`~examples/statistics/bxp_demo.py`
5858

59+
Added a bool kwarg, `manage_xticks`, which if False disables the management
60+
of the xtick and xlim by `boxplot`.
5961

6062
Support for datetime axes in 2d plots
6163
`````````````````````````````````````

lib/matplotlib/axes/_axes.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28752875
bootstrap=None, usermedians=None, conf_intervals=None,
28762876
meanline=False, showmeans=False, showcaps=True,
28772877
showbox=True, showfliers=True, boxprops=None, labels=None,
2878-
flierprops=None, medianprops=None, meanprops=None):
2878+
flierprops=None, medianprops=None, meanprops=None,
2879+
manage_xticks=True):
28792880
"""
28802881
Make a box and whisker plot.
28812882
@@ -3060,14 +3061,15 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
30603061
showcaps=showcaps, showbox=showbox,
30613062
boxprops=boxprops, flierprops=flierprops,
30623063
medianprops=medianprops, meanprops=meanprops,
3063-
meanline=meanline, showfliers=showfliers)
3064+
meanline=meanline, showfliers=showfliers,
3065+
manage_xticks=manage_xticks)
30643066
return artists
30653067

30663068
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30673069
patch_artist=False, shownotches=False, showmeans=False,
30683070
showcaps=True, showbox=True, showfliers=True,
30693071
boxprops=None, flierprops=None, medianprops=None,
3070-
meanprops=None, meanline=False):
3072+
meanprops=None, meanline=False, manage_xticks=True):
30713073
"""
30723074
Drawing function for box and whisker plots.
30733075
@@ -3077,7 +3079,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30773079
patch_artist=False, shownotches=False, showmeans=False,
30783080
showcaps=True, showbox=True, showfliers=True,
30793081
boxprops=None, flierprops=None, medianprops=None,
3080-
meanprops=None, meanline=False)
3082+
meanprops=None, meanline=False, manage_xticks=True)
30813083
30823084
Make a box and whisker plot for each column of *x* or each
30833085
vector in sequence *x*. The box extends from the lower to
@@ -3156,6 +3158,9 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
31563158
*meanprops*. Not recommended if *shownotches* is also True.
31573159
Otherwise, means will be shown as points.
31583160
3161+
manage_xticks : bool, default = True
3162+
If the function should adjust the xlim and xtick locations.
3163+
31593164
Returns
31603165
-------
31613166
@@ -3390,10 +3395,11 @@ def dopatch(xs, ys, **kwargs):
33903395
setlim = self.set_ylim
33913396
setlabels = self.set_yticklabels
33923397

3393-
newlimits = min(positions) - 0.5, max(positions) + 0.5
3394-
setlim(newlimits)
3395-
setticks(positions)
3396-
setlabels(datalabels)
3398+
if manage_xticks:
3399+
newlimits = min(positions) - 0.5, max(positions) + 0.5
3400+
setlim(newlimits)
3401+
setticks(positions)
3402+
setlabels(datalabels)
33973403

33983404
# reset hold status
33993405
self.hold(holdStatus)

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import matplotlib
1414
from matplotlib.testing.decorators import image_comparison, cleanup
1515
import matplotlib.pyplot as plt
16-
16+
from numpy.testing import assert_array_equal
1717

1818
@image_comparison(baseline_images=['formatter_ticker_001',
1919
'formatter_ticker_002',
@@ -1460,6 +1460,20 @@ def test_boxplot_bad_ci_2():
14601460
conf_intervals=[[1, 2], [1]])
14611461

14621462

1463+
@cleanup
1464+
def test_manage_xticks():
1465+
_, ax = plt.subplots()
1466+
ax.set_xlim(0, 4)
1467+
old_xlim = ax.get_xlim()
1468+
np.random.seed(0)
1469+
y1 = np.random.normal(10, 3, 20)
1470+
y2 = np.random.normal(3, 1, 20)
1471+
ax.boxplot([y1, y2], positions = [1,2],
1472+
manage_xticks=False)
1473+
new_xlim = ax.get_xlim()
1474+
assert_array_equal(old_xlim, new_xlim)
1475+
1476+
14631477
@image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed'])
14641478
def test_errorbar():
14651479
x = np.arange(0.1, 4, 0.5)

0 commit comments

Comments
 (0)