HomeLinuxSeaborn Rotate Axis Labels

Seaborn Rotate Axis Labels


In Python, the “matplotlib” and the “seaborn” libraries are utilized for the visualization of information. Customers can draw a number of kinds of graphs through the use of the “matplotlib” library, akin to scatter, bar, line, and plenty of extra. Likewise, the “seaborn” library affords varied visualization patterns and makes a speciality of statistics visualization.

This text will talk about in regards to the seaborn rotate axis labels in Python.

Rotate Axis Labels Utilizing “ticklabels()” Operate in Seaborn Plot?

To rotate the axis labels of the seaborn plot through the use of the “ticklabels()” operate, first, import the “pandas” library. Then, use the “DataFrame()” methodology to create an information body in response to want and retailer it within the “df” variable. After that, apply the “print()” assertion to view the generated knowledge body:

import pandas as pd

df = pd.DataFrame({‘Scholar’: [‘Maria’, ‘Maria’, ‘Maria’, ‘David’, ‘David’, ‘David’,
                  ‘Peter’, ‘Peter’, ‘Filps’, ‘Long_name_Rohan_amna_tani’],
                ‘Marks’: [22, 14, 9, 7, 7, 20, 12, 30, 34, 19]})
print(df)

 
It may be noticed that the info body has been created efficiently:


Now, import the “seaborn” library and name the “countplot()” methodology that takes two parameters, akin to knowledge that holds the info body and the column title as a second variable:

import seaborn as sns

plot = sns.countplot(knowledge=df, x=‘Scholar’)

 
Within the supplied output, the graph has been plotted efficiently with regular labels positions:


Subsequent, apply the “ticklabels()” methodology that takes two parameters, such because the title of the specified part and the “rotation” parameter that holds the rotation angle/worth. As an example, we need to rotate the x-axis labels to 30:

plot.set_xticklabels(plot.get_xticklabels(), rotation=30)

 
In response to the supplied output, the x-axis labels are rotated efficiently:


You may have realized the simplest methodology to rotate the seaborn plot axis labels place in Python.

Conclusion

To rotate the seaborn plot axis labels place, the “ticklabels()” methodology can be utilized in Python. The seaborn gives a number of determine customization and the “ticklabels()” methodology as tick labels on each axes is one in all them. This text described the process to rotate the seaborn plot axis labels place in Python.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments