Use Axes.tick_params/Axis.set_tick_params more#8678
Use Axes.tick_params/Axis.set_tick_params more#8678tacaswell merged 4 commits intomatplotlib:masterfrom
Conversation
| ticklabels = ax.get_xticklabels() + ax.get_yticklabels() | ||
|
|
||
| for line in ticklines: | ||
| line.set_linewidth(3) |
There was a problem hiding this comment.
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.
Probably we just didn't use it much when this was first written.
There was a problem hiding this comment.
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.
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
| 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.
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.
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.
| # 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.
The you had it might be better.
There was a problem hiding this comment.
Well, we need which='both' or the test fails, unless you mean bottom instead of 1?
There was a problem hiding this comment.
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