Skip to content

FIX: logscale + subplots share axes #9000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,14 +1173,16 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
if sharex in ["col", "all"]:
# turn off all but the bottom row
for ax in axarr[:-1, :].flat:
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.set_tick_params(which='both',
label1On=False, label2On=False)
ax.xaxis.offsetText.set_visible(False)
if sharey in ["row", "all"]:
# turn off all but the first column
for ax in axarr[:, 1:].flat:
for label in ax.get_yticklabels():
for label in ax.get_yticklabels(which='both'):
label.set_visible(False)
ax.yaxis.set_tick_params(which='both',
label1On=False, label2On=False)
ax.yaxis.offsetText.set_visible(False)

if squeeze:
Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,24 @@ def test_invalid_figure_size():

with pytest.raises(ValueError):
fig.add_axes((.1, .1, .5, np.nan))


def test_subplots_shareax_loglabels():
fig, ax_arr = plt.subplots(2, 2, sharex=True, sharey=True, squeeze=False)
for ax in ax_arr.flatten():
ax.plot([10, 20, 30], [10, 20, 30])

ax.set_yscale("log")
ax.set_xscale("log")

for ax in ax_arr[0, :]:
assert 0 == len(ax.xaxis.get_ticklabels(which='both'))

for ax in ax_arr[1, :]:
assert 0 < len(ax.xaxis.get_ticklabels(which='both'))

for ax in ax_arr[:, 1]:
assert 0 == len(ax.yaxis.get_ticklabels(which='both'))

for ax in ax_arr[:, 0]:
assert 0 < len(ax.yaxis.get_ticklabels(which='both'))