我有一个数据框(df),如下所示:
df
Year Capacity Qty
0 2010 4,999 and under 2
1 2010 5,000-6,000 1
2 2010 6,100-7,000 3
3 2011 4,999 and under 5
4 2011 5,000-6,000 3
5 2011 6,100-7,000 3
....
94 2019 4,999 and under 1
95 2019 5,000-6,000 3
96 201 6,100-7,000 4
我想在网格中生成子图,每年一次。每个图都有x轴=“容量”,y轴=“数量”。
g = sns.FacetGrid(df, col="Year", col_wrap=3, height=4, aspect=1)
g.map(sns.barplot, "BTU_Rating", "qty")
如何添加“容量”列中列出的x刻度标签?
答案 0 :(得分:1)
g.set_xticklabels(rotation=x)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.FacetGrid(df, col="Year", col_wrap=3, height=4, aspect=1)
order = ['4,999 and under', '5,000-6,000', '6,100-7,000']
g.map(sns.barplot, "Capacity", "Qty", order=order)
g.set_xticklabels(rotation=90)
plt.show()