温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - How to rotate x-axis tick labels in Pandas barplot
matplotlib pandas python

python - 如何在Pandas barplot中旋转x轴刻度标签

发布于 2020-06-12 15:32:09

使用以下代码:

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)
plt.xlabel("")

我做了这个情节:

在此处输入图片说明

如何将x轴刻度标签旋转到0度?

我尝试添加它,但是没有用:

plt.set_xticklabels(df.index,rotation=90)

查看更多

提问者
neversaint
被浏览
94
EdChum 2015-08-27 16:18

传递参数rot=0以旋转xticks:

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()

产量图:

在此处输入图片说明