Created
September 1, 2017 12:12
-
-
Save sergiolucero/ef20ebf860a58eb5d3b2091de08eeae0 to your computer and use it in GitHub Desktop.
Plotting bike clusters
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 | |
from util import zload | |
import pandas as pd | |
cluster_data = zload('Labels_16.il') | |
loc_data = pd.read_excel('georef.xlsx') | |
loc_dict = loc_data.T.to_dict() # transformed | |
centroid = (loc_data.lat.median(),loc_data.lon.median()) | |
bikemap = folium.Map(location=centroid,tiles='cartodbpositron',zoom_start=14) | |
COLORS = ['red', 'darkred', 'lightred', 'yellow', 'darkorange', | |
'orange', 'darkpurple', 'purple', 'lightpurple', 'blue', 'pink', | |
'magenta', 'black', 'darkgreen', 'lightgreen', 'green'] # use a freaking colormap: https://matplotlib.org/examples/color/colormaps_reference.html | |
cluster_ids = set(cluster_data) | |
for cid in cluster_ids: | |
cluster_stations = [ix for ix, jx in enumerate(cluster_data) if jx==cid] | |
cluster_color = COLORS[cid] | |
print('plotting %d stations with cluster_id=%d (COLOR=%s)' %(len(cluster_stations), cid, cluster_color)) | |
for station in cluster_stations: | |
cdata = loc_dict[cid] | |
icon = folium.Icon(color = cluster_color) | |
# folium.Marker(location=[cdata['lat'],cdata['lon']],icon=icon).add_to(bikemap) | |
bikemap.add_child(folium.Marker([cdata['lat'],cdata['lon']], | |
# popup = folium.Popup(station_html), | |
icon=folium.Icon(color = cluster_color) | |
)) | |
bikemap.save('blc_clusters.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment