简体   繁体   English

如何在 altair 中隐藏彩条/图例?

[英]How to hide colorbar/legend in altair?

Is there a way to hide the color bar on Altair?有没有办法隐藏 Altair 上的颜色条?

Specifically, I want to get rid of the amount_spent one, without deleting the gradiente on the mark_bar .具体来说,我想摆脱amount_spent一个,而不删除mark_bar上的 gradiente。 Is this possible?这可能吗?

Here's the code:这是代码:

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"
)

Output: Output:

在此处输入图像描述

Yes, you can do this by setting the legend property of the color encoding to None ;是的,您可以通过将color编码的legend属性设置为None来做到这一点; that is, replace this:也就是说,替换这个:

color='amount_spent'

with this:有了这个:

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

See Adjusting the Legend in the Altair documentation for more information.有关详细信息,请参阅 Altair 文档中的调整图例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM