问题描述
我有一个带有梯度图例的NPS值的条形图。我想同时显示带有传奇的mark_rule的一些静态值,最后对结果进行方面分析。但是,我找不到不复制图例或忽略渐变图例的方法。
我不确定该错误是否与之相关,这很相似,但是没有一个例子与我的类似:https://github.com/vega/vega-lite/issues/5996
非常感谢您的帮助!
import pandas as pd
import altair as alt
df = pd.DataFrame({
'Name': ['PlaceA','PlaceB','PlaceC','PlaceA','PlaceC'],'NPS': [58,75,100,76,80,92,90,72],'Month': [1,1,2,3,3],'Target': [75,75]
})
bars = alt.Chart(df).mark_bar().encode(
y = alt.Y(
'Month:N'
),x=alt.X(
'NPS',axis=None
),color=alt.Color(
'NPS',scale=alt.Scale(
scheme='redyellowgreen',domain=[0,100]
),legend=alt.Legend(
title='NPS'
)
)
)
# All was fine with this setting,except for the missing legend
lines1 = alt.Chart(df).mark_rule(color='red').encode(
x='Target'
)
# This otherwise optimal solution duplicates all the legends.
lines2 = alt.Chart(df).transform_fold(
['Target']
).mark_rule().encode(
x='value:Q',color=alt.Color(
'key:N',scale=alt.Scale(
range=['red']
),legend=alt.Legend(
title=None
)
)
)
# Most simple code for duplicating the legends.
lines3 = alt.Chart(df).mark_rule().encode(
x='Target:Q',color='Target:N'
)
alt.layer(
lines2,bars,width=200
).facet(
facet=alt.Facet(
'Name:N',title=None
),columns=3
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)