python - 如何为 seaborn FacetGrid 和图形级 xtick 标签设置旋转

标签 python pandas seaborn

我有一个如下所示的数据框 (df):

import pandas as pd
import seaborn as sns

data = {'Year': [2010, 2010, 2010, 2011, 2011, 2011, 2019, 2019, 2019],
        'Capacity': ['4,999 and under', '5,000-6,000', '6,100-7,000', '4,999 and under', '5,000-6,000', '6,100-7,000', '4,999 and under', '5,000-6,000', '6,100-7,000'],
        'Qty': [2, 1, 3, 5, 3, 3, 1, 3, 4]}

df = pd.DataFrame(data)

我想在网格中生成子图,每年一个图。每个地 block 都有 x='Capacity', y='Qty'

g = sns.FacetGrid(df, col="Year", col_wrap=3, height=4, aspect=1)
g.map(sns.barplot, "BTU_Rating", "qty")

如何添加 "Capacity" 列中列出的 xtick 标签?

感谢您的帮助。

enter image description here

最佳答案

  • 指定g.set_xticklabels(rotation=x)

更新的答案

import pandas as pd
import seaborn as sns

order = ['4,999 and under', '5,000-6,000', '6,100-7,000']
g = sns.catplot(data=df, col='Year', x='Capacity', y='Qty', order=order, kind='bar', col_wrap=3, height=4, aspect=1)
g.set_xticklabels(rotation=90)

enter image description here

原始答案

import pandas as pd
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)

enter image description here

关于python - 如何为 seaborn FacetGrid 和图形级 xtick 标签设置旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61601588/

相关文章:

python - 在 Python 中使用 RSA 公钥进行签名许可证 key 验证

python2.5多处理池

python - Plotly Python - 标签值格式化

python - 专门在 seaborn 集群图中更改热图的大小?

python - 使用 groupby 时迭代列以生成条形图

python - 定期勾选标签

Python 扭曲的 sendLine()

python - Django 扩展 - dumpscript 无法正常工作

python - pandas 将其他列乘以另一个列

python-2.7 - 根据确切日期按季节对数据进行分组