Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Created September 1, 2017 12:12
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/ef20ebf860a58eb5d3b2091de08eeae0 to your computer and use it in GitHub Desktop.
Save sergiolucero/ef20ebf860a58eb5d3b2091de08eeae0 to your computer and use it in GitHub Desktop.
Plotting bike clusters
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