close

How to rotate x-axis tick labels in Pandas barplot

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to rotate x-axis tick labels in Pandas barplot in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to rotate x-axis tick labels in Pandas barplot?

  1. How to rotate x-axis tick labels in Pandas barplot?

    You can use set_xticklabels()
    ax.set_xticklabels(df['Names'], rotation=90, ha='right')

  2. rotate x-axis tick labels in Pandas barplot

    You can use set_xticklabels()
    ax.set_xticklabels(df['Names'], rotation=90, ha='right')

Method 1

Pass param rot=0 to rotate the xticklabels:

import matplotlib
matplotlib.style.use('ggplot')
import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({ 'celltype':["foo","bar","qux","woz"], 's1':[5,9,1,7], 's2':[12,90,13,87]})
df = df[["celltype","s1","s2"]]
df.set_index(["celltype"],inplace=True)
df.plot(kind='bar',alpha=0.75, rot=0)
plt.xlabel("")
plt.show()

yields plot:

enter image description here

Method 2

You can use set_xticklabels()

ax.set_xticklabels(df['Names'], rotation=90, ha='right')

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read