question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Altair choropleth map, color highlight based on line chart selection

See original GitHub issue

Hi!

I am plotting a choropleth map colored by the field Passenger_0_ and a line chart showing the evolution of Passenger_0_ throughout a day by zone.

I would like to select a line (zone) in the line chart and have it highlighted in the map and vice versa (select a zone in the map and have it highlighted in the line chart).

For now, I am able to change the whole color of the map when selecting the line, but have no clue of how to only change the color of the selected area.

I would appreciate any help. This is the code:

dict_json = json.loads(long_df[long_df['hour']==0].to_json())

colours_obj = alt.Color('properties.Passenger_0_:Q',
              scale=alt.Scale(scheme='yelloworangered'),
             title = "Pickups")

sel_line_hover = alt.selection_single(on='mouseover', empty='none')
sel_line_col = alt.selection_single()
sel_line_size = alt.selection_single(empty='none')

base = alt.Chart(alt.Data(values=dict_json['features'])).mark_geoshape(
    stroke='black',
    strokeWidth=1
    ).encode(
    color=alt.condition(sel_line_col, colours_obj, alt.value('lightgray')),
    tooltip = ['properties.zone:O',
               'properties.Passenger_0_:Q']
    ).properties(
    width=350,
    height=750,
    ).add_selection(
    sel_line_col
    )

line = alt.Chart(long_df).mark_line().encode(
    x='hour',
    y='Passenger_0_',
    color=alt.condition(sel_line_hover|sel_line_col, 'zone', alt.value('lightgray')),
    size=alt.condition(sel_line_hover|sel_line_size, alt.value(4),alt.value(1)),
    tooltip = ['zone:O']
    ).properties(
    width=250,
    height=750,
    ).add_selection(
    sel_line_hover,sel_line_col,sel_line_size
    )

base | line

altair_map_and_linechart_st

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
angelrpscommented, Feb 4, 2021

Thank you very much for your answer @joelostblom I haven´t had time to try your solution but I will close this issue until I test it.

0reactions
joelostblomcommented, Feb 3, 2021

Answered on SO.. @angelrps if my reply there solves your problem, could you close this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Altair choropleth map, color highlight based on line chart ...
I would like to select a line ( zone ) in the line chart and have it highlighted in the map and vice...
Read more >
Altair Choropleth Map, Color Highlight Based On ... - ADocLib
This gallery contains a selection of examples of the plots Altair can create. glance but they are built by combining a simple set...
Read more >
Interactive choropleth maps in python using Altair, Plotly and ...
A Step by step guide to create interactive map visuals in python using opensource libraries - Altair, Plotly and Folium .
Read more >
Example Gallery — Altair 4.2.0 documentation
This gallery contains a selection of examples of the plots Altair can create. ... Bar Chart with Highlighted Bar Bar Chart with Labels...
Read more >
Guide to Altair Panopticon 2021.2 Visualizations
Trending performance between two numeric variables Numeric Line Graph ... A Heat Map is a special type of color-based data visualization that is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found