Skip to content

Commit c6bbfe9

Browse files
tacaswellQuLogic
authored andcommitted
FIX: logscale + subplots share axes
Use `set_tick_params` to hide tick labels in not-edge plots instead of setting the visibility on the tick label objects. This catches both major and minor tick-labels and is more robust to changes in the ticklabel generation. closes #8903
1 parent 7c5e705 commit c6bbfe9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/matplotlib/figure.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,14 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
11731173
if sharex in ["col", "all"]:
11741174
# turn off all but the bottom row
11751175
for ax in axarr[:-1, :].flat:
1176-
ax.xaxis.set_tick_params(labelbottom=False)
1176+
ax.xaxis.set_tick_params(which='both',
1177+
labelbottom=False, labeltop=False)
11771178
ax.xaxis.offsetText.set_visible(False)
11781179
if sharey in ["row", "all"]:
11791180
# turn off all but the first column
11801181
for ax in axarr[:, 1:].flat:
1181-
ax.yaxis.set_tick_params(labelleft=False)
1182+
ax.yaxis.set_tick_params(which='both',
1183+
labelleft=False, labelright=False)
11821184
ax.yaxis.offsetText.set_visible(False)
11831185

11841186
if squeeze:

lib/matplotlib/tests/test_figure.py

+21
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,24 @@ def test_invalid_figure_size():
298298

299299
with pytest.raises(ValueError):
300300
fig.add_axes((.1, .1, .5, np.nan))
301+
302+
303+
def test_subplots_shareax_loglabels():
304+
fig, ax_arr = plt.subplots(2, 2, sharex=True, sharey=True, squeeze=False)
305+
for ax in ax_arr.flatten():
306+
ax.plot([10, 20, 30], [10, 20, 30])
307+
308+
ax.set_yscale("log")
309+
ax.set_xscale("log")
310+
311+
for ax in ax_arr[0, :]:
312+
assert 0 == len(ax.xaxis.get_ticklabels(which='both'))
313+
314+
for ax in ax_arr[1, :]:
315+
assert 0 < len(ax.xaxis.get_ticklabels(which='both'))
316+
317+
for ax in ax_arr[:, 1]:
318+
assert 0 == len(ax.yaxis.get_ticklabels(which='both'))
319+
320+
for ax in ax_arr[:, 0]:
321+
assert 0 < len(ax.yaxis.get_ticklabels(which='both'))

0 commit comments

Comments
 (0)