[英]How to replace the axis label in altair?
我想將軸標簽從 [0,0.5,1] 更改為 ['infrequent','average','frequent'] ,如下所示:
我嘗試如下進行更改,但它不起作用。
alt.Chart(df).mark_circle().encode(
alt.X('x:Q',
axis=alt.Axis(values=['infrequent','average','frequent']),title="A's frequency"),
alt.Y('y:Q',
axis=alt.Axis(values=['infrequent','average','frequent']),title="B's frequency"),
color=alt.Color('s:Q',scale=alt.Scale(domain=[0, 1],scheme="redyellowblue")),
tooltip=['term',
alt.Tooltip('cat:Q', title="Occurence in A"),
alt.Tooltip('ncat:Q', title="Occurence in B"),
alt.Tooltip('s:Q', title="Score close to A",format='.2')]
).properties(
width=300,
height=300
)
任何人都可以給我一些建議嗎? 提前致謝。
您可以使用與此 VegaLite 示例中相同的方法和labelExpr
字符串:
axis_labels = (
"datum.label == 0 ? 'Infrequent'
: datum.label == 0.5 ? 'Average'
: 'Frequent'"
)
alt.X('x:Q',axis=alt.Axis(labelExpr=axis_labels))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.