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

How to rotate x-axis tick labels in Pandas barplot


Pass param rot=0 to rotate the xticks:

import matplotlibmatplotlib.style.use('ggplot')import matplotlib.pyplot as pltimport pandas as pddf = 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


Try this -

plt.xticks(rotation=90)

enter image description here


You can use set_xticklabels()

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