-1

For example, given the various months columns containing temperatures per specific region, how can I change the heatmap based on each month using drop down menu? I already have a map built using the geodataframe.explore(column = 'col_name').

Thanks!

Isaac A
  • 543
  • 1
  • 6
  • 18
  • I think you're getting a lot of downvotes because this is an extremely broad question. You might get a better response if you post the code you have, explain more specifically what you're trying to do (e.g. are you building a webpage? or trying to use widgets in jupyterlab?) and explain what you've tried so far. – Michael Delgado Jun 02 '22 at 01:46
  • Hello, good point. I would have posted a code if I knew what code to use. Geopandas is totally new to me. – Isaac A Jun 02 '22 at 03:33

1 Answers1

2

If you're working in jupyterlab, this is pretty easy! You can combine a ipywidgets.Output widget with a ipywidgets.Dropdown to set up your canvas, then capture the follium map with the output. You then need to link them by adding an event handler.

import geopandas as gpd
import ipywidgets
from IPython.display import HTML, display

df = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))

out = ipywidgets.Output(layout={'border': '1px solid black'})

w = ipywidgets.Dropdown(
    options=df.columns.values.tolist(),
    value=df.columns.values[0],
    description='Column:',
    disabled=False,
)

def on_dropdown_change(change):
    out.clear_output()
    with out:
        display(df.explore(w.value, cmap="Blues"))

w.observe(on_dropdown_change, names='value')
display(w)

with out:
    display(df.explore(df.columns[0], cmap="Blues"))

out

folium/leaflet world map with dropdown widget for selecting columns

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54