Skip to content

Instantly share code, notes, and snippets.

@radupotop
Created November 18, 2024 18:31
Show Gist options
  • Save radupotop/bae6853ce994316dce248ae70c6662f6 to your computer and use it in GitHub Desktop.
Save radupotop/bae6853ce994316dce248ae70c6662f6 to your computer and use it in GitHub Desktop.
Folium map plot
import folium
import pandas as pd
from folium.plugins import MarkerCluster
# Load the CSV file into a Pandas DataFrame
csv_file = 'sl4.csv' # Replace with your CSV file path
data = pd.read_csv(csv_file)
# Initialize a Folium map centered on the average latitude and longitude
average_latitude = data['latitude'].mean()
average_longitude = data['longitude'].mean()
map_center = [average_latitude, average_longitude]
mymap = folium.Map(location=map_center, zoom_start=6)
# Add marker clustering
marker_cluster = MarkerCluster().add_to(mymap)
# Iterate through the data and add points to the map
for index, row in data.iterrows():
latitude = row['latitude']
longitude = row['longitude']
datetime_value = row['datetime']
popup_text = (
f"Date/Time: {datetime_value}<br>Latitude: {latitude}<br>Longitude: {longitude}"
)
# Add marker to the cluster
folium.Marker(location=[latitude, longitude], popup=popup_text).add_to(marker_cluster)
# Save the map to an HTML file
output_html = 'map.html' # The output HTML file
mymap.save(output_html)
print(f"Map has been saved to {output_html}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment