Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Last active August 23, 2017 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiolucero/958bf9a50f17f4b8e0ae67b3123e6354 to your computer and use it in GitHub Desktop.
Save sergiolucero/958bf9a50f17f4b8e0ae67b3123e6354 to your computer and use it in GitHub Desktop.
de Bici Las Condes a Folium
import folium
import pandas as pd
URL = 'https://www.bicilascondes.cl/availability_map/getJsonObject'
COLORS = ['red', 'darkred', 'lightred', 'yellow',
'darkgreen', 'lightgreen', 'green'] # low is bad->red, high is good->green
bike_data = pd.read_json(URL)
bikemap = folium.Map(bike_data[['lat','lon']].mean().tolist(), # data centroid
tiles = 'Stamen Terrain', zoom_start = 15)
for station_id, station_data in bike_data.iterrows():
station_html = folium.Html('<b>%s</b>' %(pd.DataFrame(station_data).to_html()),
script=True)
station_color = COLORS[int(station_data.bikes/len(COLORS))] # not quite right
bikemap.add_child(folium.Marker([station_data.lat,station_data.lon],
popup = folium.Popup(station_html),
icon=folium.Icon(color=station_color)
))
bikemap.save('mapa_blc.html')
@sergiolucero
Copy link
Author

COLORS should be from a matplotlib.colormap:
https://matplotlib.org/examples/color/colormaps_reference.html

@sergiolucero
Copy link
Author

goodcolorsblc

@sergiolucero
Copy link
Author

the map above shows the availability of bikes (slots can be inferred), red is bad, green is good! A lot more than the code above has been used to produce, for instance, the lines showing good neighbours for bad stations.

@sergiolucero
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment