diff --git a/CHANGELOG b/CHANGELOG index 8d1418215c30..a93c3ea9c660 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ 2014-03-27 Added tests for pie ccw parameter. Removed pdf and svg images from tests for pie linewidth parameter. +2014-03-24 Added bool kwarg (manage_xticks) to boxplot to enable/disable + the managemnet of the xlimits and ticks when making a boxplot. + Default in True which maintains current behavior by default. + 2014-03-22 Added the keyword arguments wedgeprops and textprops to pie. Users can control the wedge and text properties of the pie in more detail, if they choose. diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 341ac381c617..b17bee40faae 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -56,6 +56,8 @@ kwargs. See the examples: :ref:`~examples/statistics/boxplot_demo.py` and :ref:`~examples/statistics/bxp_demo.py` +Added a bool kwarg, `manage_xticks`, which if False disables the management +of the xtick and xlim by `boxplot`. Support for datetime axes in 2d plots ````````````````````````````````````` diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 6b8ad4549ad8..029af02c5d26 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2875,7 +2875,8 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5, bootstrap=None, usermedians=None, conf_intervals=None, meanline=False, showmeans=False, showcaps=True, showbox=True, showfliers=True, boxprops=None, labels=None, - flierprops=None, medianprops=None, meanprops=None): + flierprops=None, medianprops=None, meanprops=None, + manage_xticks=True): """ Make a box and whisker plot. @@ -3060,14 +3061,15 @@ def boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5, showcaps=showcaps, showbox=showbox, boxprops=boxprops, flierprops=flierprops, medianprops=medianprops, meanprops=meanprops, - meanline=meanline, showfliers=showfliers) + meanline=meanline, showfliers=showfliers, + manage_xticks=manage_xticks) return artists def bxp(self, bxpstats, positions=None, widths=None, vert=True, patch_artist=False, shownotches=False, showmeans=False, showcaps=True, showbox=True, showfliers=True, boxprops=None, flierprops=None, medianprops=None, - meanprops=None, meanline=False): + meanprops=None, meanline=False, manage_xticks=True): """ Drawing function for box and whisker plots. @@ -3077,7 +3079,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True, patch_artist=False, shownotches=False, showmeans=False, showcaps=True, showbox=True, showfliers=True, boxprops=None, flierprops=None, medianprops=None, - meanprops=None, meanline=False) + meanprops=None, meanline=False, manage_xticks=True) Make a box and whisker plot for each column of *x* or each 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, *meanprops*. Not recommended if *shownotches* is also True. Otherwise, means will be shown as points. + manage_xticks : bool, default = True + If the function should adjust the xlim and xtick locations. + Returns ------- @@ -3390,10 +3395,11 @@ def dopatch(xs, ys, **kwargs): setlim = self.set_ylim setlabels = self.set_yticklabels - newlimits = min(positions) - 0.5, max(positions) + 0.5 - setlim(newlimits) - setticks(positions) - setlabels(datalabels) + if manage_xticks: + newlimits = min(positions) - 0.5, max(positions) + 0.5 + setlim(newlimits) + setticks(positions) + setlabels(datalabels) # reset hold status self.hold(holdStatus) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index aca809fa742b..9258ff2c3533 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -13,7 +13,7 @@ import matplotlib from matplotlib.testing.decorators import image_comparison, cleanup import matplotlib.pyplot as plt - +from numpy.testing import assert_array_equal @image_comparison(baseline_images=['formatter_ticker_001', 'formatter_ticker_002', @@ -1433,9 +1433,8 @@ def test_boxplot_bad_medians_1(): fig, ax = plt.subplots() assert_raises(ValueError, ax.boxplot, x, usermedians=[1, 2]) - @cleanup -def test_boxplot_bad_medians_1(): +def test_boxplot_bad_medians_2(): x = np.linspace(-7, 7, 140) x = np.hstack([-25, x, 25]) fig, ax = plt.subplots() @@ -1460,6 +1459,20 @@ def test_boxplot_bad_ci_2(): conf_intervals=[[1, 2], [1]]) +@cleanup +def test_manage_xticks(): + _, ax = plt.subplots() + ax.set_xlim(0, 4) + old_xlim = ax.get_xlim() + np.random.seed(0) + y1 = np.random.normal(10, 3, 20) + y2 = np.random.normal(3, 1, 20) + ax.boxplot([y1, y2], positions = [1,2], + manage_xticks=False) + new_xlim = ax.get_xlim() + assert_array_equal(old_xlim, new_xlim) + + @image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed']) def test_errorbar(): x = np.arange(0.1, 4, 0.5)