8000 Tick label rotation via `set_tick_params` by bcongdon · Pull Request #6829 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Tick label rotation via set_tick_params #6829

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
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
Next Next commit
set_tick_params now responds to
  • Loading branch information
bcongdon committed Jul 25, 2016
commit 6dfb8cc77d4256d0ace44b52bd570b9bf6e4b110
Empty file.
10 changes: 8 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, axes, loc, label,
pad=None,
labelsize=None,
labelcolor=None,
labelrotation=0,
Copy link
Member

Choose a reason for hiding this comment

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

Please put last so to preserve API

zorder=None,
gridOn=None, # defaults to axes.grid depending on
# axes.grid.which
Expand Down Expand Up @@ -139,6 +140,8 @@ def __init__(self, axes, loc, label,
labelsize = rcParams['%s.labelsize' % name]
self._labelsize = labelsize

self._labelrotation = labelrotation

if zorder is None:
if major:
zorder = mlines.Line2D.zorder + 0.01
Expand Down Expand Up @@ -333,7 +336,7 @@ def _apply_params(self, **kw):
self.tick1line.set_markeredgewidth(v)
self.tick2line.set_markeredgewidth(v)
label_list = [k for k in six.iteritems(kw)
if k[0] in ['labelsize', 'labelcolor']]
if k[0] in ['labelsize', 'labelcolor', 'labelrotation']]
if label_list:
label_kw = dict([(k[5:], v) for (k, v) in label_list])
self.label1.set(**label_kw)
Expand Down Expand Up @@ -798,14 +801,17 @@ def _translate_tick_kw(kw, to_init_kw=True):
'labelsize', 'labelcolor', 'zorder', 'gridOn',
'tick1On', 'tick2On', 'label1On', 'label2On']
kwkeys1 = ['length', 'direction', 'left', 'bottom', 'right', 'top',
'labelleft', 'labelbottom', 'labelright', 'labeltop']
'labelleft', 'labelbottom', 'labelright', 'labeltop',
'rotation']
kwkeys = kwkeys0 + kwkeys1
kwtrans = dict()
if to_init_kw:
if 'length' in kw:
kwtrans['size'] = kw.pop('length')
if 'direction' in kw:
kwtrans['tickdir'] = kw.pop('direction')
if 'rotation' in kw:
kwtrans['labelrotation'] = kw.pop('rotation')
if 'left' in kw:
kwtrans['tick1On'] = _string_to_bool(kw.pop('left'))
if 'bottom' in kw:
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,18 @@ def test_bar_color_cycle():
assert ccov(ln.get_color()) == ccov(br.get_facecolor())


@cleanup
def test_tick_param_label_rotation():
fix, ax = plt.subplots()
plt.plot([0, 1], [0, 1])
ax.xaxis.set_tick_params(which='both', rotation=75)
ax.yaxis.set_tick_params(which='both', rotation=90)
for text in ax.get_xticklabels(which='both'):
assert text.get_rotation() == 75
for text in ax.get_yticklabels(which='both'):
assert text.get_rotation() == 90


if __name__ == '__main__':
import nose
import sys
Expand Down
0