Skip to content

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

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented May 28, 2017

PR Summary

This PR replaces a lot of manual loops over ticks/tick labels with calls to Axes.tick_params/Axis.set_tick_params. These methods work on all ticks at the same time and using them will allow for some optimization in a later PR.

Ping @choldgraf since most of these are examples and to make sure I didn't botch anything there.

PR Checklist

  • Has Pytest style unit tests (existing ones, anyway)
  • Code is PEP 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • [N/A] Added an entry to doc/users/whats_new.rst if major new feature
  • [N/A] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogic QuLogic added this to the 2.1 (next point release) milestone May 28, 2017
ticklabels = ax.get_xticklabels() + ax.get_yticklabels()

for line in ticklines:
line.set_linewidth(3)
Copy link
Member Author

Choose a reason for hiding this comment

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

As noted in the documentation above, this was actually wrong, since ticks use markers.

@QuLogic
Copy link
Member Author

QuLogic commented May 30, 2017

@tacaswell these are the sorts of things I was talking about on gitter.

it is important to know that in Matplotlib, the ticks are *markers*. All
:class:`~matplotlib.lines.Line2D` objects support a line (solid, dashed, etc)
and a marker (circle, square, tick). The tick width is controlled by the
"markeredgewidth" property::
Copy link
Contributor

Choose a reason for hiding this comment

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

why not `` ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably we just didn't use it much when this was first written.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I just noticed the below example doesn't actually use markeredgewidth...

line.set_alpha(0.9)
line.set_ls('-')
line.set_color('0.5')
ax.tick_params(labelbottom=False, labeltop=False,
Copy link
Contributor

Choose a reason for hiding this comment

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

I had no idea this was possible...cool!

@choldgraf
Copy link
Contributor

LGTM. Nice job on reducing the total number of lines in matplotlib 👍 :)

@QuLogic
Copy link
Member Author

QuLogic commented May 31, 2017

In cleaning up the doc things you mentioned, I noticed that I had not updated the tutorials. However, the tutorials actually hit one of the shortcomings of ax.tick_params: it works on both tick markers and tick labels, so it only supports a limited set of options for each. Thus the tutorial that sets horizontal alignment is not possible directly with ax.tick_params. We probably need to come up with some new API to encompass these sorts of things.

Ironically, when the tutorials explain why to use ax.get_tick*, it's actually a reason to avoid using it (at least for any interactive plots.)

@QuLogic
Copy link
Member Author

QuLogic commented May 31, 2017

Fixed the doc comment, and I'm going to leave the tutorial stuff until after we've finalized the other API changes.

@@ -561,8 +560,7 @@ def set_rgrids(self, radii, labels=None, angle=None, fmt=None,
if angle is None:
angle = self.get_rlabel_position()
self.set_rlabel_position(angle)
for t in self.yaxis.get_ticklabels():
t.update(kwargs)
self.yaxis.set_tick_params(which='major', **kwargs)
Copy link
Contributor

@anntzer anntzer Jun 30, 2017

Choose a reason for hiding this comment

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

Is this really equivalent? (It probably should, but we all know how consistent the API is) set_tick_params ultimately forwards the arguments to Tick._apply_params, which is different from Tick.update (i.e. Artist.update).

Copy link
Member Author

@QuLogic QuLogic Aug 8, 2017

Choose a reason for hiding this comment

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

Unfortunately, you're right to be suspicious. There's a loop through the input to check that the keys are valid for ticks, and that doesn't necessarily allow all possible Text arguments that the original code did.

@QuLogic QuLogic mentioned this pull request Aug 7, 2017
2 tasks
@@ -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!

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 matplotlib#8903
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants