除了将数据清理为整洁的格式之外,还需要将文本数据(百分比)重新格式化为数字数据类型.由于这与条形图无关,我假设您可以自己处理并专注于绘图和数据结构:
df = pandas.DataFrame({
'Factor': ['Growth', 'Value'],
'Weight': [0.10, 0.20],
'Variance': [0.15, 0.35]
})
fig, ax1 = pyplot.subplots(figsize=(10, 10))
tidy = (
df.set_index('Factor')
.stack() # un-pivots the data
.reset_index() # moves all data out of the index
.rename(columns={'level_1': 'Variable', 0: 'Value'})
)
seaborn.barplot(x='Factor', y='Value', hue='Variable', data=tidy, ax=ax1)
seaborn.despine(fig)