17 | def rotateTickLabels(ax, rotation, which, rotation_mode="anchor", ha="right"): |
18 | """ Rotates the ticklabels of a matplotlib Axes |
19 | |
20 | Parameters |
21 | ---------- |
22 | ax : matplotlib Axes |
23 | The Axes object that will be modified. |
24 | rotation : float |
25 | The amount of rotation, in degrees, to be applied to the labels. |
26 | which : string |
27 | The axis whose ticklabels will be rotated. Valid values are 'x', |
28 | 'y', or 'both'. |
29 | rotation_mode : string, optional |
30 | The rotation point for the ticklabels. Highly recommended to use |
31 | the default value ('anchor'). |
32 | ha : string |
33 | The horizontal alignment of the ticks. Again, recommended to use |
34 | the default ('right'). |
35 | |
36 | Returns |
37 | ------- |
38 | None |
39 | |
40 | """ |
41 | |
42 | if which == "both": |
43 | rotateTickLabels(ax, rotation, "x", rotation_mode=rotation_mode, ha=ha) |
44 | rotateTickLabels(ax, rotation, "y", rotation_mode=rotation_mode, ha=ha) |
45 | else: |
46 | if which == "x": |
47 | axis = ax.xaxis |
48 | |
49 | elif which == "y": |
50 | axis = ax.yaxis |
51 | |
52 | for t in axis.get_ticklabels(): |
53 | t.set_horizontalalignment(ha) |
54 | t.set_rotation(rotation) |
55 | t.set_rotation_mode(rotation_mode) |