[Python] Altair graph with conditional tooltip

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I want to use 'tooltip' to show information depending on the type of point in the plot. I noticed that 'tooltip' accepts 'condition'. Therefore, I'm trying to use 'tooltip' together with 'alt.condition', but without success. Below is my attempt:

    import altair as alt
    from vega_datasets import data

    source = data.cars()

    chart = alt.Chart(source).mark_circle(size=60).encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
    tooltip=alt.condition(
    alt.datum.Origin == 'EUA',
    ['Name', 'Horsepower'],
    ['Name', 'Miles_per_Gallon']
    )
    )

    chart.save('tooltip.html')


    Is there any solution for this?

    Continue reading...

Compartilhe esta Página