In [2]:
Copied!
import folium
from folium.plugins import HeatMap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, titles='CartoDB Positron')
# Add heatmap layer to the map
HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), radius=8, max_zoom=13, opacity=2).add_to(map)
# Save the map to an HTML file
map.save('covid19heatmapfinal2.html')
import folium
from folium.plugins import HeatMap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, titles='CartoDB Positron')
# Add heatmap layer to the map
HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), radius=8, max_zoom=13, opacity=2).add_to(map)
# Save the map to an HTML file
map.save('covid19heatmapfinal2.html')
In [ ]:
Copied!
# Cholera Heatmap Final Code
### This code was meant to add a legend and a box in the corner explaining where the data is from, it took a few itterations, but the last block of code did what was needed
# Cholera Heatmap Final Code
### This code was meant to add a legend and a box in the corner explaining where the data is from, it took a few itterations, but the last block of code did what was needed
In [6]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), "blur": 19, "maxZoom": 13, "minOpacity": 0.99, "opacity": 3, "radius": 15).add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 100px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>Legend</b><br>
Some text here<br>
Another text here<br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('isthiscovid.html')
import folium
from folium.plugins import HeatMap, MiniMap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), "blur": 19, "maxZoom": 13, "minOpacity": 0.99, "opacity": 3, "radius": 15).add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
Legend
Some text here
Another text here
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('isthiscovid.html')
Some text here
Another text here
Cell In[6], line 12 HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), "blur": 19, "maxZoom": 13, "minOpacity": 0.99, "opacity": 3, "radius": 15).add_to(map) ^ SyntaxError: positional argument follows keyword argument
In [ ]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), radius=15, max_zoom=13, opacity=3)
heatmap_layer.add_to(map)
# Create a linear color map
color_map = LinearColormap(['green', 'yellow', 'red'], vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 100px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>COVID-19 Origin</b><br>
Data retrieved from Michael Woroby's initial COVID-19 origin study<br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('finalcovid.html')
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), radius=15, max_zoom=13, opacity=3)
heatmap_layer.add_to(map)
# Create a linear color map
color_map = LinearColormap(['green', 'yellow', 'red'], vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
COVID-19 Origin
Data retrieved from Michael Woroby's initial COVID-19 origin study
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('finalcovid.html')
Data retrieved from Michael Woroby's initial COVID-19 origin study
In [10]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur: 19, maxZoom: 13, minOpacity: 0.99, opacity: 3, radius: 15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 100px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>Legend</b><br>
Some text here<br>
Another text here<br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCovidHeatmap.html')
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='CartoDB Positron')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur: 19, maxZoom: 13, minOpacity: 0.99, opacity: 3, radius: 15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
Legend
Some text here
Another text here
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCovidHeatmap.html')
Some text here
Another text here
Cell In[10], line 13 heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur: 19, maxZoom: 13, minOpacity: 0.99, opacity: 3, radius: 15) ^ SyntaxError: positional argument follows keyword argument
In [21]:
Copied!
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='OpenStreetMap')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=13, min_opacity=0.99, opacity=0.3, radius=15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: 100px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color:white; opacity:0.8;
padding: 10px;">
<b>COVID-19 Origin</b>
<br> Data retrieved from Michael Woroby's initial COVID-19 origin study<br>
</div>
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCovidHeatmap.html')
import folium
from folium.plugins import HeatMap, MiniMap
from branca.colormap import LinearColormap
import pandas as pd
# Load data from CSV file
data = pd.read_csv('covid19.csv')
# Create a base map
map = folium.Map(location=[data['latitude'].mean(), data['longitude'].mean()], zoom_start=10, tiles='OpenStreetMap')
# Add heatmap layer to the map
heatmap_layer = HeatMap(data=data[['latitude', 'longitude', 'confirmed']].groupby(['latitude', 'longitude']).sum().reset_index().values.tolist(), blur=19, max_zoom=13, min_opacity=0.99, opacity=0.3, radius=15)
heatmap_layer.add_to(map)
# Create a custom colormap
colors = ['#C0C0FF', '#008000', '#FFFF00', '#FF0000']
color_map = LinearColormap(colors=colors, vmin=data['confirmed'].min(), vmax=data['confirmed'].max())
# Add the color bar to the map
color_map.caption = 'Confirmed Cases'
color_map.add_to(map)
# Add a text box or legend to the corner of the map
legend_html = """
COVID-19 Origin
Data retrieved from Michael Woroby's initial COVID-19 origin study
"""
map.get_root().html.add_child(folium.Element(legend_html))
# Add a minimap to the map
minimap = MiniMap()
map.add_child(minimap)
# Save the map to an HTML file
map.save('FinalCovidHeatmap.html')
Data retrieved from Michael Woroby's initial COVID-19 origin study
In [ ]:
Copied!
Last update:
2023-08-08