如何在altair中隐藏颜色栏/图例?

2024-03-28 09:09:51 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法隐藏牵牛星上的颜色栏

具体来说,我想去掉amount_spent一个,而不删除mark_bar上的gradiente。这可能吗

代码如下:

alt.Chart(df_1).mark_bar().encode(
    x = alt.X('amount_spent:Q', title = "Monto gastado en MXN"),
    y = alt.Y('page_name:N', sort='-x', title = " "),
    color='amount_spent',
).transform_window(
  rank='rank(amout_spent))',
  sort=[alt.SortField('amount_spent', order='descending')]
).transform_filter(
  alt.datum.rank <= 20
).properties(
    width = 800,
    height= 500,
    title = "Monto gastado en MXN por página de FB"
)

输出:

enter image description here


Tags: title颜色bartransformaltsortamounten
1条回答
网友
1楼 · 发布于 2024-03-28 09:09:51

是的,您可以通过将color编码的legend属性设置为None来实现这一点;也就是说,替换这个:

color='amount_spent'

为此:

color=alt.Color('amount_spent', legend=None)

有关更多信息,请参阅Altair文档中的Adjusting the Legend

相关问题 更多 >