- Import libraries: We import pathlib for handling file paths, JSON for parsing the GeoJSON data, and plotly.graph_objects for creating the visualization.
- Load GeoJSON data: We use pathlib.Path to create a path object for the GeoJSON file and then open it and load the contents into a Python dictionary using JSON.loads(). Extract data: We extract the latitude, longitude, and magnitude values from the GeoJSON data and store them in separate lists.
- Create the map: We create a go.Scattergeo object using Plotly, specifying the latitude, longitude, and magnitude values. We set the marker size and color based on the magnitude, using the Viridis color scale and adding a colorbar to indicate the magnitude range. We update the layout of the figure to set the title, scope, and appearance of the map.
- Finally, we use fig.show() to display the map. This code will create an interactive map showing the locations of recent earthquakes, with marker size and color representing the magnitude. You can customize the map further by adjusting the color scale, adding more details, or using different types of markers.
llemgo/Python-projects-repo
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|