【发布时间】:2018-10-05 10:13:26
【问题描述】:
我有以下dataframe
import pandas as pd
from plotnine import *
df = pd.DataFrame({
'variable': ['gender', 'gender', 'age', 'age', 'age', 'income', 'income', 'income', 'income'],
'category': ['Female', 'Male', '1-24', '25-54', '55+', 'Lo', 'Lo-Med', 'Med', 'High'],
'value': [60, 40, 50, 30, 20, 10, 25, 25, 40],
})
df['variable'] = pd.Categorical(df['variable'], categories=['gender', 'age', 'income'])
我正在使用以下代码来获取堆积条形图
(ggplot(df, aes(x='variable', y='value', fill='category'))
+ geom_col()
)
以上代码取自here
如何将标签(在本例中为 values)放在每个栏的每个类别的中间?
【问题讨论】:
-
有什么理由不想要 matplotlib?如果您很灵活,this 解决方案可能会对您有所帮助。此外,您共享的链接包含示例,如果您向下滚动,它们会在顶部用值注释条
-
标签在条的顶部,而不是在堆叠条的中间:(
标签: python python-3.x plotnine