Last active
August 23, 2017 16:53
-
-
Save sergiolucero/958bf9a50f17f4b8e0ae67b3123e6354 to your computer and use it in GitHub Desktop.
de Bici Las Condes a Folium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
COLORS should be from a matplotlib.colormap:
https://matplotlib.org/examples/color/colormaps_reference.html