简体   繁体   中英

How to hide colorbar/legend in altair?

Is there a way to hide the color bar on Altair?

Specifically, I want to get rid of the amount_spent one, without deleting the gradiente on the mark_bar . 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:

在此处输入图像描述

Yes, you can do this by setting the legend property of the color encoding to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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