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

Skip to content

Commit 8fc41f8

Browse files
committed
Merge pull request #2922 from tacaswell/boxplot_manage_xlim
ENH : add flag to box_plot and bxp to manage (or not) xticks
2 parents 1ae63b5 + 80b3692 commit 8fc41f8

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

CHANGELOG

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

18+
2014-03-24 Added bool kwarg (manage_xticks) to boxplot to enable/disable
19+
the managemnet of the xlimits and ticks when making a boxplot.
20+
Default in True which maintains current behavior by default.
21+
1822
2014-03-22 Added the keyword arguments wedgeprops and textprops to pie.
1923
Users can control the wedge and text properties of the pie
2024
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
@@ -64,6 +64,8 @@ kwargs. See the examples:
6464
:ref:`~examples/statistics/boxplot_demo.py` and
6565
:ref:`~examples/statistics/bxp_demo.py`
6666

67+
Added a bool kwarg, `manage_xticks`, which if False disables the management
68+
of the xtick and xlim by `boxplot`.
6769

6870
Support for datetime axes in 2d plots
6971
`````````````````````````````````````

lib/matplotlib/axes/_axes.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,8 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
28882888
bootstrap=None, usermedians=None, conf_intervals=None,
28892889
meanline=False, showmeans=False, showcaps=True,
28902890
showbox=True, showfliers=True, boxprops=None, labels=None,
2891-
flierprops=None, medianprops=None, meanprops=None):
2891+
flierprops=None, medianprops=None, meanprops=None,
2892+
manage_xticks=True):
28922893
"""
28932894
Make a box and whisker plot.
28942895
@@ -3073,14 +3074,15 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
30733074
showcaps=showcaps, showbox=showbox,
30743075
boxprops=boxprops, flierprops=flierprops,
30753076
medianprops=medianprops, meanprops=meanprops,
3076-
meanline=meanline, showfliers=showfliers)
3077+
meanline=meanline, showfliers=showfliers,
3078+
manage_xticks=manage_xticks)
30773079
return artists
30783080

30793081
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30803082
patch_artist=False, shownotches=False, showmeans=False,
30813083
showcaps=True, showbox=True, showfliers=True,
30823084
boxprops=None, flierprops=None, medianprops=None,
3083-
meanprops=None, meanline=False):
3085+
meanprops=None, meanline=False, manage_xticks=True):
30843086
"""
30853087
Drawing function for box and whisker plots.
30863088
@@ -3090,7 +3092,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
30903092
patch_artist=False, shownotches=False, showmeans=False,
30913093
showcaps=True, showbox=True, showfliers=True,
30923094
boxprops=None, flierprops=None, medianprops=None,
3093-
meanprops=None, meanline=False)
3095+
meanprops=None, meanline=False, manage_xticks=True)
30943096
30953097
Make a box and whisker plot for each column of *x* or each
30963098
vector in sequence *x*. The box extends from the lower to
@@ -3169,6 +3171,9 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
31693171
*meanprops*. Not recommended if *shownotches* is also True.
31703172
Otherwise, means will be shown as points.
31713173
3174+
manage_xticks : bool, default = True
3175+
If the function should adjust the xlim and xtick locations.
3176+
31723177
Returns
31733178
-------
31743179
@@ -3403,10 +3408,11 @@ def dopatch(xs, ys, **kwargs):
34033408
setlim = self.set_ylim
34043409
setlabels = self.set_yticklabels
34053410

3406-
newlimits = min(positions) - 0.5, max(positions) + 0.5
3407-
setlim(newlimits)
3408-
setticks(positions)
3409-
setlabels(datalabels)
3411+
if manage_xticks:
3412+
newlimits = min(positions) - 0.5, max(positions) + 0.5
3413+
setlim(newlimits)
3414+
setticks(positions)
3415+
setlabels(datalabels)
34103416

34113417
# reset hold status
34123418
self.hold(holdStatus)

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 3 deletions
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',
@@ -1433,9 +1433,8 @@ def test_boxplot_bad_medians_1():
14331433
fig, ax = plt.subplots()
14341434
assert_raises(ValueError, ax.boxplot, x, usermedians=[1, 2])
14351435

1436-
14371436
@cleanup
1438-
def test_boxplot_bad_medians_1():
1437+
def test_boxplot_bad_medians_2():
14391438
x = np.linspace(-7, 7, 140)
14401439
x = np.hstack([-25, x, 25])
14411440
fig, ax = plt.subplots()
@@ -1460,6 +1459,20 @@ def test_boxplot_bad_ci_2():
14601459
conf_intervals=[[1, 2], [1]])
14611460

14621461

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

0 commit comments

Comments
 (0)