Skip to content

Commit 0147b51

Browse files
committed
Merge pull request #7457 from sinhrks/axlayout
BUG: Better axis label handling for partial layout
2 parents 0b6ea39 + ab704d3 commit 0147b51

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

doc/source/v0.14.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Performance
149149
- Regression in groupby aggregation of datetime64 dtypes (:issue:`7555`)
150150
- Improvements in `MultiIndex.from_product` for large iterables (:issue:`7627`)
151151

152-
152+
- Bug in subplots displays ``ticklabels`` and ``labels`` in different rule (:issue:`5897`)
153153

154154

155155

pandas/tests/test_graphics.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,12 @@ def test_plot(self):
822822

823823
axes = _check_plot_works(df.plot, subplots=True, title='blah')
824824
self._check_axes_shape(axes, axes_num=3, layout=(3, 1))
825+
for ax in axes[:2]:
826+
self._check_visible(ax.get_xticklabels(), visible=False)
827+
self._check_visible([ax.xaxis.get_label()], visible=False)
828+
for ax in [axes[2]]:
829+
self._check_visible(ax.get_xticklabels())
830+
self._check_visible([ax.xaxis.get_label()])
825831

826832
_check_plot_works(df.plot, title='blah')
827833

@@ -2331,8 +2337,16 @@ def test_grouped_box_layout(self):
23312337
column='height', return_type='dict')
23322338
self._check_axes_shape(self.plt.gcf().axes, axes_num=3, layout=(2, 2))
23332339

2334-
box = df.boxplot(column=['height', 'weight', 'category'], by='gender')
2340+
# GH 5897
2341+
axes = df.boxplot(column=['height', 'weight', 'category'], by='gender',
2342+
return_type='axes')
23352343
self._check_axes_shape(self.plt.gcf().axes, axes_num=3, layout=(2, 2))
2344+
for ax in [axes['height']]:
2345+
self._check_visible(ax.get_xticklabels(), visible=False)
2346+
self._check_visible([ax.xaxis.get_label()], visible=False)
2347+
for ax in [axes['weight'], axes['category']]:
2348+
self._check_visible(ax.get_xticklabels())
2349+
self._check_visible([ax.xaxis.get_label()])
23362350

23372351
box = df.groupby('classroom').boxplot(
23382352
column=['height', 'weight', 'category'], return_type='dict')

pandas/tools/plotting.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3022,15 +3022,16 @@ def on_right(i):
30223022

30233023
if nplots > 1:
30243024
if sharex and nrows > 1:
3025-
for i, ax in enumerate(axarr):
3026-
if np.ceil(float(i + 1) / ncols) < nrows: # only last row
3027-
[label.set_visible(
3028-
False) for label in ax.get_xticklabels()]
3025+
for ax in axarr[:naxes][:-ncols]: # only bottom row
3026+
for label in ax.get_xticklabels():
3027+
label.set_visible(False)
3028+
ax.xaxis.get_label().set_visible(False)
30293029
if sharey and ncols > 1:
30303030
for i, ax in enumerate(axarr):
30313031
if (i % ncols) != 0: # only first column
3032-
[label.set_visible(
3033-
False) for label in ax.get_yticklabels()]
3032+
for label in ax.get_yticklabels():
3033+
label.set_visible(False)
3034+
ax.yaxis.get_label().set_visible(False)
30343035

30353036
if naxes != nplots:
30363037
for ax in axarr[naxes:]:

0 commit comments

Comments
 (0)