In [18]:
import pandas as pd 
import folium
import vincent, json
import numpy as np
df=pd.read_csv("/Users/yiling10/Downloads/TestData.csv")
#make the folium map
map=folium.Map(location=[df['LAT'].mean(),df['LON'].mean()],zoom_start=6,tiles='stamenterrain')

#Separate the data based on the categories
def Color(name):
    if name =='C1' :
        col='green'
    elif name == 'C2' :
        col='orange'
    else:
        col='red'
    return col

#make the vincent chart for category 
df_group=df.groupby('CAT')
df_group_sum=df_group['QUANT1','QUANT2','QUANT3'].sum()
group=vincent.GroupedBar(df_group_sum,width=350,height=200)
group.legend(title='QUANT')
group.colors(brew='Pastel1')
group.axis_titles(x='Categories', y='Sum of the Quant')

#make the vincent line chart for datetime
df_group2=df.groupby('DATE')
df_group_sum2=df_group2['QUANT1','QUANT2','QUANT3'].sum()
lines = vincent.Line(df_group_sum2,width=350,height=200)
lines.scales[0].type = 'ordinal'
lines.axis_titles(x='Datetime', y='Sum of the Quant')
lines.legend(title='Categories')

#add quant1 on the map
fg=folium.FeatureGroup(name="QUANT1")
for lat,lon,cat,num,num_2,num_3,name in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT1'],df['QUANT2'],df['QUANT3'],df['NAME']):
    #make the html click popup
    html="""
NAME: {}<br>
QUANT1: {}<br>
QUANT2: {}<br>
QUANT3: {}<br>
CAT: {}<br>
    """
    html = html.format(name,num,num_2,num_3,cat)
    test = folium.IFrame(html, width=150, height=100)
    fg.add_child(folium.CircleMarker(location=[lat,lon],popup=(folium.Popup(test)),radius=num/10,color=Color(cat),fill_color=Color(cat)))
map.add_child(fg)

#add quant2 on the map
fh=folium.FeatureGroup(name="QUANT2,Categories Chart")
for lat,lon,name,num2 in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT2']):
    #make the groupbar chart click popup
    popup= folium.Popup(max_width=800)
    folium.Vega(group, height=250, width=450).add_to(popup)
    fh.add_child(folium.RegularPolygonMarker(location=[lat,lon],popup=popup,radius=num2/10,color=Color(name),fill_color=Color(name),number_of_sides=3))
map.add_child(fh)

#add quant3 on the map
fk=folium.FeatureGroup(name="QUANT3,Datetime Chart")
for lat,lon,name,num3 in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT3']):
    #make the line chart click popup
    popup = folium.Popup(max_width=800)
    folium.Vega(lines, height=250, width=450).add_to(popup)
    fk.add_child(folium.RegularPolygonMarker(location=[lat,lon],popup=popup,radius=num3/10,color=Color(name),fill_color=Color(name),number_of_sides=4))
map.add_child(fk)

#add population background on the map
map.add_child(folium.GeoJson(data=open('/Users/yiling10/Downloads/world_geojson_from_ogr.json'),
name="Population",
style_function=lambda x: {'fillColor':'green' if x['properties']['POP2005'] <= 10000000 else 'orange' if 10000000 < x['properties']['POP2005'] < 20000000 else 'red'}))

#add layer contraller
map.add_child(folium.LayerControl())


Out[18]:

In [19]:
import pandas as pd 
import folium
import vincent, json
import numpy as np
df=pd.read_csv("/Users/yiling10/Downloads/TestData.csv")
#make the folium map
map=folium.Map(location=[df['LAT'].mean(),df['LON'].mean()],zoom_start=6,tiles='stamenterrain')

#Separate the data based on the categories
def Color(name):
    if name =='C1' :
        col='green'
    elif name == 'C2' :
        col='orange'
    else:
        col='red'
    return col

#make the vincent chart for category 
df_group=df.groupby('CAT')
df_group_sum=df_group['QUANT1','QUANT2','QUANT3'].sum()
group=vincent.GroupedBar(df_group_sum,width=350,height=200)
group.legend(title='QUANT')
group.colors(brew='Pastel1')
group.axis_titles(x='Categories', y='Sum of the Quant')

#make the vincent line chart for datetime
df_group2=df.groupby('DATE')
df_group_sum2=df_group2['QUANT1','QUANT2','QUANT3'].sum()
lines = vincent.Line(df_group_sum2,width=350,height=200)
lines.scales[0].type = 'ordinal'
lines.axis_titles(x='Datetime', y='Sum of the Quant')
lines.legend(title='Categories')

#add quant1 on the map
fg=folium.FeatureGroup(name="QUANT1")
for lat,lon,cat,num,num_2,num_3,name in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT1'],df['QUANT2'],df['QUANT3'],df['NAME']):
    #make the html click popup
    html="""
NAME: {}<br>
QUANT1: {}<br>
QUANT2: {}<br>
QUANT3: {}<br>
CAT: {}<br>
    """
    html = html.format(name,num,num_2,num_3,cat)
    test = folium.IFrame(html, width=150, height=100)
    fg.add_child(folium.CircleMarker(location=[lat,lon],popup=(folium.Popup(test)),radius=num/10,color=Color(cat),fill_color=Color(cat)))
map.add_child(fg)

#add quant2 on the map
fh=folium.FeatureGroup(name="QUANT2,Categories Chart")
for lat,lon,name,num2 in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT2']):
    #make the groupbar chart click popup
    popup= folium.Popup(max_width=800)
    folium.Vega(group, height=250, width=450).add_to(popup)
    fh.add_child(folium.RegularPolygonMarker(location=[lat,lon],popup=popup,radius=num2/10,color=Color(name),fill_color=Color(name),number_of_sides=3))
map.add_child(fh)

#add quant3 on the map
fk=folium.FeatureGroup(name="QUANT3,Datetime Chart")
for lat,lon,name,num3 in zip(df['LAT'],df['LON'],df['CAT'],df['QUANT3']):
    #make the line chart click popup
    popup = folium.Popup(max_width=800)
    folium.Vega(lines, height=250, width=450).add_to(popup)
    fk.add_child(folium.RegularPolygonMarker(location=[lat,lon],popup=popup,radius=num3/10,color=Color(name),fill_color=Color(name),number_of_sides=4))
map.add_child(fk)

#add population background on the map
map.add_child(folium.GeoJson(data=open('/Users/yiling10/Downloads/world_geojson_from_ogr.json'),
name="Population",
style_function=lambda x: {'fillColor':'green' if x['properties']['POP2005'] <= 10000000 else 'orange' if 10000000 < x['properties']['POP2005'] < 20000000 else 'red'}))

#add layer contraller
map.add_child(folium.LayerControl())

#save the map as html file
map.save(outfile='part3map_3.0.html')

In [ ]:


In [ ]: