You’ll be able to worth please see modest syntax to rotate the axis labels in a plot in seaborn:
my_plot.set_xticklabels(my_plot.get_xticklabels(), rotation=45)
Please see instance presentations tips on how to worth this syntax in apply.
Instance: Rotate Axis Labels in Seaborn Plot
Think now we have please see pandas DataFrame that incorporates details about the issues scored via basketball gamers on diverse groups:
import pandas as pd
#form DataFrame
df = pd.DataFrame({'workforce': ['Mavericks', 'Mavericks', 'Mavericks',
                            'Mavericks', 'Warriors', 'Warriors',
                            'Blazers', 'Blazers', 'Kings',
                            'some_really_really_long_name'],
                   'issues': [22, 14, 9, 7, 29, 20, 30, 34, 19, 12]})
#view DataFrame
print(df)
                           workforce  issues
0                     Mavericks      22
1                     Mavericks      14
2                     Mavericks       9
3                     Mavericks       7
4                      Warriors      29
5                      Warriors      20
6                       Blazers      30
7                       Blazers      34
8                         Kings      19
9  some_really_really_long_name      12
We will worth the countplot() serve as in seaborn to form a plot that presentations the depend of every workforce within the DataFrame:
import seaborn as sns #form seaborn countplot my_plot = sns.countplot(knowledge=df, x='workforce')
 
Since some of the workforce names is very lengthy, it overlaps any other workforce title at the x-axis.
To get round this, we will worth please see code to rotate the x-axis labels:
import seaborn as sns #form seaborn countplot my_plot = sns.countplot(knowledge=df, x='workforce') #rotate x-axis labels my_plot.set_xticklabels(my_plot.get_xticklabels(), rotation=45)
 
Understand that every of the x-axis labels at the moment are circled 45 levels.
If we’d like, we will additionally worth the horizontalalignment argument to shift the x-axis labels to the left:
import seaborn as sns #form seaborn countplot my_plot = sns.countplot(knowledge=df, x='workforce') #rotate x-axis labels my_plot.set_xticklabels(my_plot.get_xticklabels(), rotation=45, horizontalalignment="proper")
 
Each and every of the x-axis labels are circled 45 levels and shifted to the left.
Word: You probably have bother uploading seaborn in a Jupyter pocket book, chances are you’ll first wish to run the command %pip set up seaborn.
Spare Sources
Please see tutorials give an explanation for tips on how to carry out alternative familiar duties in seaborn:
 Upload a Identify to Seaborn Plots
 Alternate Font Dimension in Seaborn Plots
 Alter the Determine Dimension of a Seaborn Plot


 
							





