Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use Axes.tick_params/Axis.set_tick_params more #8678

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

Merged
merged 4 commits into from
Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
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
  • Loading branch information
tacaswell authored and QuLogic committed Aug 11, 2017
commit c6bbfe9e7c13baab6c41d2a217aadfdb66f05e4f
6 changes: 4 additions & 2 deletions 6 lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,12 +1173,14 @@ 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:
ax.xaxis.set_tick_params(labelbottom=False)
ax.xaxis.set_tick_params(which='both',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The you had it might be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we need which='both' or the test fails, unless you mean bottom instead of 1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I wrote this I went back and forth on if removing all of the labels vs just the bottom and left was overkill.

'labelbottom' and 'labelleft' are certainly more readable!

labelbottom=False, labeltop=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:
ax.yaxis.set_tick_params(labelleft=False)
ax.yaxis.set_tick_params(which='both',
labelleft=False, labelright=False)
ax.yaxis.offsetText.set_visible(False)

if squeeze:
Expand Down
21 changes: 21 additions & 0 deletions 21 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'))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.