【发布时间】:2023-01-20 09:04:29
【问题描述】:
我正在尝试在条形图上创建带有标签的条形图。标签的位置和标签的颜色取决于数据框的列。另外,我想按列给条形图上色。
我的数据:
data = {
'Survived': ['0', '1'],
'count': [500, 100],
'label_position': ['R', 'L']
}
df = pd.DataFrame(data)
我试图创建以下情节:
import seaborn.objects as so
p = (
so.Plot(df, x='count', y='Survived')
.add(so.Bar(alpha=1), color='Survived')
.add(
so.Text({"fontweight": "bold"}),
text='count',
halign='label_position',
color="label_position"
)
.scale(
halign={'L':'left', 'R':'right'},
color={'L':'black', 'R':'white'}
)
)
p.plot()
但是此代码引发以下错误:
PlotSpecError: Scale setup failed for the `color` variable. See the traceback above for more information.
因为两个可视化都有属性颜色。
我可以同时使用颜色条或文本,但不能同时使用。
彩条: color the bars
彩色文字: color the text
有没有可能把两者都涂上颜色?
【问题讨论】: