Created
April 24, 2020 10:33
-
-
Save ShayanRiyaz/8b8c4aff01665efa775e4ab0fcd717db to your computer and use it in GitHub Desktop.
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 matplotlib.colors as colors | |
from matplotlib.colors import rgb2hex | |
# create map | |
map_clusters = folium.Map(location=[latitude, longitude], zoom_start=10) | |
# set color scheme for the clusters | |
x = np.arange(kclusters) | |
ys = [i + x + (i*x)**2 for i in range(kclusters)] | |
colors_array = cm.rainbow(np.linspace(0, 1, len(ys))) | |
rainbow = [colors.rgb2hex(i) for i in colors_array] | |
rainbow[2]='#006000' | |
rainbow[1]='#006ff6' | |
# add markers to the map | |
markers_colors = [] | |
for lat, lon, poi, cluster in zip(la_merged['Latitude'], la_merged['Longitude'], la_merged['Neighbourhood'], la_merged['Cluster Label']): | |
label = folium.Popup(str(poi) + ' Cluster ' + str(cluster), parse_html=True) | |
folium.CircleMarker( | |
[lat, lon], | |
radius=5, | |
popup=label, | |
color=rainbow[cluster-2], | |
fill=True, | |
fill_color=rainbow[cluster-2], | |
fill_opacity=0.7).add_to(map_clusters) | |
legend_html = ''' | |
<div style="position: fixed; | |
bottom: 100px; left: 50px; width: 120px; height: 100px; | |
border:3px solid black; z-index:9999; font-size:13px; | |
"> Green - Cluster 0 <br> | |
Red - Cluster 1 <br> | |
Purple - Cluster 2 <br> | |
Blue - Cluster 3 </i> | |
</div> | |
''' | |
map_clusters.get_root().html.add_child(folium.Element(legend_html)) | |
map_clusters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment