How to use 'seaborn rotate axis labels' in Python

Every line of 'seaborn rotate axis labels' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17def 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)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1516def _add_axis_labels(self):
1517 """Add labels to the left and bottom Axes."""
1518 for ax, label in zip(self.axes[-1, :], self.x_vars):
1519 ax.set_xlabel(label)
1520 for ax, label in zip(self.axes[:, 0], self.y_vars):
1521 ax.set_ylabel(label)

Related snippets