-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
ticklabels = ax.get_xticklabels() + ax.get_yticklabels() | ||
|
||
for line in ticklines: | ||
line.set_linewidth(3) |
There was a problem hiding this comment.
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.
@tacaswell these are the sorts of things I was talking about on gitter. |
doc/faq/howto_faq.rst
Outdated
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:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not `` ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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!
LGTM. Nice job on reducing the total number of lines in matplotlib 👍 :) |
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 Ironically, when the tutorials explain why to use |
Fixed the doc comment, and I'm going to leave the tutorial stuff until after we've finalized the other API changes. |
lib/matplotlib/projections/polar.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
This shortcut should be preferred over manually changing every Tick's properties.
lib/matplotlib/figure.py
Outdated
@@ -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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
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