Sharey keyword for boxplot by sorenwacker · Pull Request #20968 · pandas-dev/pandas (original) (raw)

I see where you want to go. Would this be acceptable? It uses a function that you might want somewhere else though in case you want to use it in other tests? Where would be a good position to put it?

def test_groupby_boxplot_sharex(self):

    def _assert_xtickslabels_visibility(axes, expected):
        for ax, exp in zip(axes, expected):
            self._check_visible(ax.get_xticklabels(), visible=exp)

    df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14],
                    'b': [0.56, 0.84, 0.29, 0.56, 0.85],
                    'c': [0, 1, 2, 3, 1]},
                   index=[0, 1, 2, 3, 4])

    # standart behavior
    axes = df.groupby('c').boxplot()
    expected = [True, True, True, True]
    _assert_xtickslabels_visibility(axes, expected)
    # set sharex=False should be identical
    axes = df.groupby('c').boxplot(sharex=False)
    expected = [True, True, True, True]
    _assert_xtickslabels_visibility(axes, expected)        
    # sharex=True, xticklabels should be visible only for bottom plots
    axes = df.groupby('c').boxplot(sharex=True)
    expected = [False, False, True, True]
    _assert_xtickslabels_visibility(axes, expected)´