Skip to content

Commit 63ae3bd

Browse files
committed
BUG: hidden ticklabels with sharex and secondary
1 parent 529cd3d commit 63ae3bd

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/whatsnew/v0.16.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,6 @@ Bug Fixes
161161
- Changed caching in ``AbstractHolidayCalendar`` to be at the instance level rather than at the class level as the latter can result in unexpected behaviour. (:issue:`9552`)
162162

163163
- Fixed latex output for multi-indexed dataframes (:issue:`9778`)
164+
165+
166+
- Bug in hiding ticklabels with subplots and shared axes when adding a new plot to an existing grid of axes (:issue:`9158`)

pandas/tests/test_graphics.py

+13
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,19 @@ def test_subplots_ts_share_axes(self):
15341534
for ax in axes[[0, 1, 2], [2]].ravel():
15351535
self._check_visible(ax.get_yticklabels(), visible=False)
15361536

1537+
def test_subplots_sharex_axes_existing_axes(self):
1538+
# GH 9158
1539+
d = {'A': [1., 2., 3., 4.], 'B': [4., 3., 2., 1.], 'C': [5, 1, 3, 4]}
1540+
df = DataFrame(d, index=date_range('2014 10 11', '2014 10 14'))
1541+
1542+
axes = df[['A', 'B']].plot(subplots=True)
1543+
df['C'].plot(ax=axes[0], secondary_y=True)
1544+
1545+
self._check_visible(axes[0].get_xticklabels(), visible=False)
1546+
self._check_visible(axes[1].get_xticklabels(), visible=True)
1547+
for ax in axes.ravel():
1548+
self._check_visible(ax.get_yticklabels(), visible=True)
1549+
15371550
def test_negative_log(self):
15381551
df = - DataFrame(rand(6, 4),
15391552
index=list(string.ascii_letters[:6]),

pandas/tools/plotting.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,10 @@ def _adorn_subplots(self):
10401040
if len(self.axes) > 0:
10411041
all_axes = self._get_axes()
10421042
nrows, ncols = self._get_axes_layout()
1043-
_handle_shared_axes(all_axes, len(all_axes), len(all_axes), nrows, ncols, self.sharex, self.sharey)
1043+
_handle_shared_axes(axarr=all_axes, nplots=len(all_axes),
1044+
naxes=nrows * ncols, nrows=nrows,
1045+
ncols=ncols, sharex=self.sharex,
1046+
sharey=self.sharey)
10441047

10451048
for ax in to_adorn:
10461049
if self.yticks is not None:

0 commit comments

Comments
 (0)