diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index cbd5ad3f49c18..32f2e6b626d12 100755 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -239,3 +239,6 @@ Bug Fixes - Fixed latex output for multi-indexed dataframes (:issue:`9778`) - Bug causing an exception when setting an empty range using ``DataFrame.loc`` (:issue:`9596`) + + +- Bug in hiding ticklabels with subplots and shared axes when adding a new plot to an existing grid of axes (:issue:`9158`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 7ec57c0304530..33c88b0e3b4b7 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -1534,6 +1534,19 @@ def test_subplots_ts_share_axes(self): for ax in axes[[0, 1, 2], [2]].ravel(): self._check_visible(ax.get_yticklabels(), visible=False) + def test_subplots_sharex_axes_existing_axes(self): + # GH 9158 + d = {'A': [1., 2., 3., 4.], 'B': [4., 3., 2., 1.], 'C': [5, 1, 3, 4]} + df = DataFrame(d, index=date_range('2014 10 11', '2014 10 14')) + + axes = df[['A', 'B']].plot(subplots=True) + df['C'].plot(ax=axes[0], secondary_y=True) + + self._check_visible(axes[0].get_xticklabels(), visible=False) + self._check_visible(axes[1].get_xticklabels(), visible=True) + for ax in axes.ravel(): + self._check_visible(ax.get_yticklabels(), visible=True) + def test_negative_log(self): df = - DataFrame(rand(6, 4), index=list(string.ascii_letters[:6]), diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 513f165af4686..268bd306585ad 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1040,7 +1040,10 @@ def _adorn_subplots(self): if len(self.axes) > 0: all_axes = self._get_axes() nrows, ncols = self._get_axes_layout() - _handle_shared_axes(all_axes, len(all_axes), len(all_axes), nrows, ncols, self.sharex, self.sharey) + _handle_shared_axes(axarr=all_axes, nplots=len(all_axes), + naxes=nrows * ncols, nrows=nrows, + ncols=ncols, sharex=self.sharex, + sharey=self.sharey) for ax in to_adorn: if self.yticks is not None: