From 6dfb8cc77d4256d0ace44b52bd570b9bf6e4b110 Mon Sep 17 00:00:00 2001 From: bcongdon Date: Mon, 25 Jul 2016 13:37:12 -0700 Subject: [PATCH 1/3] set_tick_params now responds to --- doc/users/whats_new/tick_params_rotation.rst | 0 lib/matplotlib/axis.py | 10 ++++++++-- lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 doc/users/whats_new/tick_params_rotation.rst diff --git a/doc/users/whats_new/tick_params_rotation.rst b/doc/users/whats_new/tick_params_rotation.rst new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index b722e2602903..e0f142dcf9eb 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -73,6 +73,7 @@ def __init__(self, axes, loc, label, pad=None, labelsize=None, labelcolor=None, + labelrotation=0, zorder=None, gridOn=None, # defaults to axes.grid depending on # axes.grid.which @@ -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 @@ -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) @@ -798,7 +801,8 @@ 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: @@ -806,6 +810,8 @@ def _translate_tick_kw(kw, to_init_kw=True): 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: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d1136e51852b..a58b06ec342b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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 From a755218dd0874268fc7955a3caf6c03816e3955a Mon Sep 17 00:00:00 2001 From: bcongdon Date: Mon, 25 Jul 2016 14:02:40 -0700 Subject: [PATCH 2/3] Added whats_new entry for axes tick rotation via set_tick_params --- doc/users/whats_new/tick_params_rotation.rst | 10 ++++++++++ lib/matplotlib/axis.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/users/whats_new/tick_params_rotation.rst b/doc/users/whats_new/tick_params_rotation.rst index e69de29bb2d1..1c90b4475896 100644 --- a/doc/users/whats_new/tick_params_rotation.rst +++ b/doc/users/whats_new/tick_params_rotation.rst @@ -0,0 +1,10 @@ +`Axis.set_tick_params` now responds to 'rotation' +------------------------------------------------- + +Bulk setting of tick label rotation is now possible via :func:`set_tick_params` using the `rotation` keyword. + +Example +``````` +:: + + ax.xaxis.set_tick_params(which='both', rotation=90) \ No newline at end of file diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index e0f142dcf9eb..276c09605a70 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -73,7 +73,6 @@ def __init__(self, axes, loc, label, pad=None, labelsize=None, labelcolor=None, - labelrotation=0, zorder=None, gridOn=None, # defaults to axes.grid depending on # axes.grid.which @@ -82,6 +81,7 @@ def __init__(self, axes, loc, label, label1On=True, label2On=False, major=True, + labelrotation=0, ): """ bbox is the Bound2D bounding box in display coords of the Axes From edbe0cce736f70773aecc064ad2df89e486ee3c3 Mon Sep 17 00:00:00 2001 From: bcongdon Date: Tue, 26 Jul 2016 09:07:51 -0700 Subject: [PATCH 3/3] Added labelrotation to tick_params docstrings --- lib/matplotlib/axes/_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 6657fd41072c..067150981971 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2665,6 +2665,9 @@ def tick_params(self, axis='both', **kwargs): Boolean or ['on' | 'off'], controls whether to draw the respective tick labels. + *labelrotation* + Tick label rotation. + Example:: ax.tick_params(direction='out', length=6, width=2, colors='r')