Global Earthquakes Analysis with Data from 1990 to 2023

Tutorial

Assisted by AI

Explore global earthquakes analysis using LightningChart Python to visualize seismic data and gain deeper insights into earthquake patterns.
Fateme Ajam

Fateme Ajam

Data Science Python Developer

LinkedIn icon
Globa-Earthquake-Analysis-Cover

Introduction

Earthquakes are among the most powerful and unpredictable natural disasters, shaping the Earth’s surface while posing significant risks to human populations and infrastructure. Understanding the patterns, frequency, and magnitude of seismic events is essential for disaster preparedness, scientific research, and policy-making.

In this analysis, we explore global earthquake trends from 1990 to 2023, using interactive visualizations to uncover key insights about seismic activity worldwide.

By leveraging LightningChart, a high-performance data visualization tool, we present a series of advanced charts and dashboards that illustrate the distribution, magnitude, and trends of earthquakes across different regions and time periods. This study aims to answer critical questions such as:

  • How have earthquake magnitudes varied over time?
  • Which regions experience the most frequent and intense seismic activity?
  • How do deep-sea and shallow earthquakes differ in magnitude distribution?
  • What patterns emerge in real-time earthquake data?

To address these questions, we have constructed a series of visualizations, including heatmaps, scatter plots, polar charts, and real-time monitoring graphs, to provide a comprehensive view of earthquake behavior.

The following sections will guide you through these findings, revealing important insights into the spatial and temporal dynamics of global seismic events.

About the Dataset

The dataset used in this analysis contains global earthquake records from 1990 to 2023, including key attributes such as date, time, magnitude, depth, location (latitude/longitude), and affected regions.

The data has been cleaned and processed to remove inconsistencies, ensuring accurate visualization and analysis. By integrating geospatial and temporal features, this dataset provides valuable insights into earthquake patterns worldwide.

LightningChart Python

LightningChart Python was chosen for this analysis due to its high-performance rendering, real-time data visualization, and advanced charting capabilities. The charts created in this study leverage LightningChart’s interactive features, allowing for dynamic updates, 3D visualizations, heatmaps.

The key advantages of LightningChart in this analysis include:

  • Real-time updates for earthquake monitoring.
  • 3D visualizations for depth, magnitude, and intensity analysis.
  • Polar and tree map charts for trend analysis across different regions and years.

With its ability to handle large datasets efficiently, LightningChart provides smooth rendering and accurate visual representation, making it an ideal tool for analyzing earthquake data.

LCPython1

Chart Types Used in the Project

In this project, we utilize various LightningChart Python chart types to explore global earthquake patterns, analyze trends, and identify significant geospatial and temporal variations:

  • Real-Time Line Charts: Used to track earthquake magnitudes over time for selected regions (e.g., Alaska, California, Washington). These charts dynamically update to reflect real-time changes in seismic activity.
  • Heatmaps: Applied to visualize earthquake frequency across different time frames and locations. Heatmaps effectively highlight high-risk zones and seasonal variations in earthquake occurrences.
  • 3D Surface & Point Charts: These 3D visualizations display earthquake intensity and depth distribution. The surface charts provide a smooth representation of magnitude variations, while the point charts map earthquakes in a geospatial context with depth analysis.
  • Treemaps: Used to categorize earthquake magnitudes by continent and country, showcasing the relative intensity of seismic activity across regions.
  • Polar Charts: These charts visualize yearly earthquake magnitude trends for the top 10 most affected countries, providing a comparative view of seismic activity over time.
  • Scatter Plots: Scatter charts plot earthquake depth against magnitude, revealing patterns in seismic activity at different crustal levels.

Setting Up Python Environment

First, you need to install Python: Download and install the latest version of Python from the official Python website.  Second, you need to import Pandas and LightningChart:

import pandas as pd
import lightningchart as lc
import time
import numpy as np

Data Loading and Preprocessing

First, we load the dataset and clean it. In our case, the dataset is a CSV file containing data on electricity access across different countries.

file_path = 'D:/DOWNLOADs/Eartquakes-1990-2023.csv'
df = pd.read_csv(file_path)

Visualizing Data with LightningChart Python

Real-Time Earthquake Magnitudes for Selected States (2023): This visualization tracks earthquake magnitudes in real-time for Alaska, California, and Washington during 2023. The line chart presents each state’s earthquake activity, with different colors representing each state. The x-axis represents time, while each state has a separate y-axis.

Results and Interpretation

  • Alaska (Blue): Exhibits frequent earthquake activity with relatively lower magnitudes.
  • California (Red): Displays higher and more frequent earthquake magnitudes.
  • Washington (Green): Experiences sporadic earthquakes, with occasional spikes in magnitude.

The moving x-axis updates dynamically, ensuring recent data remains visible while older data scrolls off.

df['datetime'] = pd.to_datetime(df['date'], errors='coerce', utc=True)
df = df.dropna(subset=['datetime', 'magnitudo'])

# Filter data for selected states and year
selected_year = 2023  
selected_states = ['Alaska', 'California', 'Washington']
filtered_data = df[df['datetime'].dt.year == selected_year]

processed_data = {
    state: filtered_data[filtered_data['state'] == state][['datetime', 'magnitudo']].sort_values(by='datetime') 
    for state in selected_states
}

# Initialize chart
chart = lc.ChartXY(theme=lc.Themes.Dark, title=f'Earthquake Magnitudes Over Time ({selected_year})')

state_series = {
    state: {
        'series': chart.add_line_series().set_name(f'{state} (Earthquakes)'),
        'timestamps': set(df_state['datetime'].astype('int64') // 10**9),
        'magnitudes': dict(zip(df_state['datetime'].astype('int64') // 10**9, df_state['magnitudo']))
    }
    for state, df_state in processed_data.items()
}

# Real-time update function
def update_data():
    for current_time in sorted(set.union(*[data['timestamps'] for data in state_series.values()])):
        for state, data in state_series.items():
            value = data['magnitudes'].get(current_time, 0)  
            data['series'].add([current_time], [value])

        time.sleep(0.001)

chart.open(live=True)
update_data()
Global-Earthquake-Analysis-Earthquake-Magnitudes

Use Case

  • Seismologists can use this visualization to monitor live earthquake trends.
  • Emergency response teams can track real-time seismic activity for better preparedness.
  • Researchers can analyze seismic behavior over time to identify patterns in earthquake intensity.

Tsunami vs. Non-Tsunami Earthquake Magnitude Distribution

This visualization compares the magnitude distribution of tsunami-generating earthquakes and non-tsunami earthquakes. The red area represents tsunami earthquakes, while the blue area represents non-tsunami earthquakes. The x-axis displays the magnitude of earthquakes, and the y-axis represents the density (normalized frequency).

Results and Interpretation

Tsunami Earthquakes (Red):

  • Tend to have higher magnitudes, mostly above 5.0, with a peak around 6.5-7.0.
  • These results indicate that stronger earthquakes are more likely to generate tsunamis.

Non-Tsunami Earthquakes (Blue):

  • Mostly below 4.0, showing a peak in lower magnitudes.
  • These earthquakes are more frequent but not strong enough to trigger tsunamis.
df['datetime'] = pd.to_datetime(df['date'], errors='coerce', utc=True)
df = df.dropna(subset=['magnitudo', 'tsunami'])

tsunami_earthquakes = df[df['tsunami'] == 1]['magnitudo']
non_tsunami_earthquakes = df[df['tsunami'] == 0]['magnitudo']

chart = lc.ChartXY(title="Comparison of Earthquake Magnitudes (Tsunami vs. Non-Tsunami)", theme=lc.Themes.Dark)

def get_density_data(values, bins=30):
    hist, bin_edges = np.histogram(values, bins=bins, density=True)
    bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
    return bin_centers.tolist(), hist.tolist()

x_tsunami, y_tsunami = get_density_data(tsunami_earthquakes)
x_non_tsunami, y_non_tsunami = get_density_data(non_tsunami_earthquakes)

chart.add_area_series().set_name("Tsunami Earthquakes").set_fill_color(lc.Color(255, 0, 0, 100)).append_samples(x_tsunami, y_tsunami)
chart.add_area_series().set_name("Non-Tsunami Earthquakes").set_fill_color(lc.Color(0, 0, 255, 100)).append_samples(x_non_tsunami, y_non_tsunami)

chart.get_default_x_axis().set_title("Magnitude")
chart.get_default_y_axis().set_title("Density")
chart.add_legend().set_position(x=90, y=75)
chart.open()
Global-Earthquake-Analysis-Tsunami

Use Case

  • Disaster Preparedness: Helps identify the threshold magnitude above which tsunamis are more likely.
  • Seismology Research: Provides insights into earthquake behaviors that generate tsunamis.
  • Risk Assessment: Authorities can use this data to improve early warning systems and mitigation strategies.

Earthquake Frequency Heatmap (2000-2023)

This heatmap visualization represents the monthly frequency of earthquakes over the years 1990 to 2023. The x-axis represents years, while the y-axis represents months, with each cell indicating the count of earthquakes in a given month-year combination.

Results & Interpretation:

Color Scale:

  • Blue indicates regions with lower earthquake activity.
  • Red highlights higher earthquake occurrences over specific months and years. 

Seasonal Trends:

  • Some months show sporadic spikes in earthquake activity (red patches), possibly due to seasonal tectonic shifts.
  • The blue-dominated areas suggest lower seismic activity in certain periods.

Long-Term Patterns:

  • The frequency of earthquakes fluctuates over the years, with some years experiencing more intense seismic activity.
  • Certain years display more earthquake occurrences across multiple months, potentially linked to tectonic shifts or increased geological movements.
heatmap_data = df.pivot_table(index="Month", columns="Year", values="magnitudo", aggfunc='count', fill_value=0)

chart = lc.ChartXY(title="Earthquake Frequency Heatmap (2000-2023)", theme=lc.Themes.Dark)
heatmap_series = chart.add_heatmap_grid_series(columns=heatmap_data.shape[1], rows=heatmap_data.shape[0])

heatmap_series.set_palette_coloring([
    {"value": float(np.min(heatmap_data.values)), "color": lc.Color(0, 0, 255)}, 
    {"value": float(np.max(heatmap_data.values)), "color": lc.Color(255, 0, 0)}
])

chart.get_default_x_axis().set_title('Year')
chart.get_default_y_axis().set_title('Month')
chart.add_legend(data=heatmap_series).set_title('Earthquake Frequency')

chart.open()
Global-Earthquake-Analysis-Heatmap

Use Case:

  • Helps in detecting seasonal or annual earthquake frequency trends.
  • Supports earthquake prediction models by analyzing past trends.

Polar Chart: Average Earthquake Magnitude by Year for Top 10 Countries

This polar chart visualizes the average earthquake magnitude over time (1990-2023) for the top 10 countries with the highest number of recorded earthquakes. Each country has a distinct line, mapping magnitude variations across different years in a circular format.

Results & Interpretation:

  • Magnitude Trends by Year:
    • Some countries show fluctuating magnitudes, indicating sporadic seismic activity spikes.
    • Others have relatively stable trends, suggesting a more consistent tectonic behavior. 
  • Pattern Analysis:
    • A radial spread suggests some years had stronger seismic activity globally.
    • A compact center cluster means magnitude variations were smaller in some regions. 
  • Notable Findings:
    • The outermost spikes indicate years of major earthquakes.
    • The innermost zones suggest lower average magnitudes over time.
chart = lc.PolarChart(theme=lc.Themes.TurquoiseHexagon, title="Average Magnitude by Year for Top 10 Countries").open(live=True)

angles = np.linspace(0, 360, len(unique_years), endpoint=False)
year_to_angle = {year: angle for year, angle in zip(unique_years, angles)}

for country in top_countries:
    line_series = chart.add_point_line_series().set_name(country)
    line_series.set_stroke(thickness=2, color=lc.Color(f'#{np.random.randint(0, 0xFFFFFF):06x}'))

    # Prepare Data
    data_points = [
        {"angle": year_to_angle[year], "amplitude": grouped_data[(grouped_data["country"] == country) & (grouped_data["year"] == year)]["magnitudo"].values[0]}
        for year in unique_years if year in grouped_data[grouped_data["country"] == country]["year"].values
    ]
    
    line_series.set_data(data_points)

chart.get_radial_axis().set_division(len(unique_years))
chart.get_radial_axis().set_tick_labels([str(year) for year in unique_years])
Global-Earthquake-Analysis-Polar-Chart

Use Case:

  • Helps seismologists analyze country-wise earthquake trends.
  • Useful for detecting years with unusual seismic activity.

Scatter Plot: Earthquake Magnitudes vs. Depth

This scatter plot visualizes the relationship between earthquake depth (x-axis) and magnitude (y-axis). Each point represents an individual earthquake, with color intensity indicating magnitude strength.

Results & Interpretation:

  • Shallow Earthquakes Dominate:
    • Most earthquakes occur at depths less than 200 km.
    • High-magnitude earthquakes (red/orange) are mainly shallow.
  • Deep Earthquakes Are Less Intense:
    • Beyond 300 km, magnitudes decrease, clustering around low-magnitude values (green/blue).
    • Few deep earthquakes reach magnitudes above 6.0.
  • A Mysterious Anomaly (Blue Line):
    • A horizontal band of low-magnitude earthquakes at uniform depth (~200 km) suggests data errors or a specific tectonic pattern.
chart = lc.ChartXY(title="Scatter Plot of Earthquakes", theme=lc.Themes.TurquoiseHexagon)

point_series = chart.add_point_series()

point_series.set_palette_point_coloring(
    steps=[
        {'value': 0.0, 'color': lc.Color('blue')},
        {'value': 2.0, 'color': lc.Color('green')},
        {'value': 4.0, 'color': lc.Color('yellow')},
        {'value': 6.0, 'color': lc.Color('orange')},
        {'value': 8.0, 'color': lc.Color('red')},
        {'value': 9.1, 'color': lc.Color('darkred')},
    ],
    look_up_property='y',
    percentage_values=False
)

point_series.add(x=depth, y=magnitude)

chart.get_default_x_axis().set_title("Depth (km)")
chart.get_default_y_axis().set_title("Magnitude")
chart.add_legend().add(chart)
chart.open()
Global-Earthquake-Analysis-ScatterPlot

Use Case:

  • Helps seismologists analyze tectonic activity at different depths.
  • Useful for identifying earthquake-prone zones based on depth distribution.
  • Can be leveraged for improving earthquake prediction models.

Global Earthquake Density Map (1990-2023)

This heatmap visualization presents the global distribution of earthquake occurrences from 1990 to 2023. The x-axis represents longitude and the y-axis represents latitude, with color intensity indicating earthquake density in different regions.

Color Scale:

  • Blue: Indicates regions with low earthquake activity.
  • Orange: Represents moderate earthquake frequency.
  • Red: Highlights seismic hotspots with high earthquake density.

Tectonic Plate Boundaries:

  • The Pacific Ring of Fire, a seismically active region, is clearly visible in red.
  • The Mid-Atlantic Ridge and Mediterranean region also display significant earthquake activity.
  • Areas along fault lines (e.g., San Andreas Fault, Himalayan region) show increased density of seismic events.

Notable Observations:

  • Sparse earthquake activity in stable continental interiors.
  • High concentration along subduction zones, suggesting intense geological activity.
df['LongitudeBin'] = pd.cut(df['longitude'], bins=100, labels=False)
df['LatitudeBin'] = pd.cut(df['latitude'], bins=100, labels=False)

heatmap_data = df.pivot_table(index="LongitudeBin", columns="LatitudeBin", values="latitude", aggfunc='count', fill_value=0)

chart = lc.ChartXY(title="Earthquake Density Map (1990-2023)", theme=lc.Themes.Dark)
heatmap_series = chart.add_heatmap_grid_series(columns=heatmap_data.shape[1], rows=heatmap_data.shape[0])

heatmap_series.set_palette_coloring([
    {"value": float(np.percentile(heatmap_data.values, 5)), "color": lc.Color(0, 0, 255)},  
    {"value": float(np.percentile(heatmap_data.values, 80)), "color": lc.Color(255, 165, 0)},  
    {"value": float(np.percentile(heatmap_data.values, 90)), "color": lc.Color(255, 0, 0)}  
])

chart.get_default_x_axis().set_title('Longitude')
chart.get_default_y_axis().set_title('Latitude')
chart.add_legend(data=heatmap_series).set_title('Number of Earthquakes')

chart.open()
Global-Earthquake-Analysis-Density-Map

Use Case:

  • Helps in mapping global seismic activity and identifying hazardous regions.
  • Supports earthquake risk assessment for urban planning and infrastructure projects.
  • Useful for seismologists and researchers studying earthquake-prone areas.

3D Earthquake Intensity and Spatial Distribution (1990-2023)

This visualization consists of two synchronized 3D charts. The left chart presents a surface representation of earthquake intensity across the globe, while the right chart is a 3D scatter plot that displays earthquake epicenters in relation to their depth.

Results & Interpretation:

  • Surface Chart (Left): The color gradient represents magnitude levels, from blue (low intensity) to red (high intensity). Areas with intense seismic activity appear as elevated peaks in the 3D landscape.
  • Scatter Chart (Right): Earthquakes are plotted based on their longitude, latitude, and depth. Deeper earthquakes appear lower in the chart, while shallower quakes are closer to the surface. Colors indicate the magnitude, with blue for weaker quakes and red for stronger ones.
dashboard = lc.Dashboard(rows=1, columns=2, theme=lc.Themes.TurquoiseHexagon)

surface_chart = dashboard.Chart3D(row_index=0, column_index=0, title="3D Earthquake Intensity Surface")
surface_series = surface_chart.add_surface_grid_series(columns=100, rows=100)
surface_series.set_palette_coloring(steps=[{"value": 4, "color": lc.Color('blue')}, {"value": 8, "color": lc.Color('red')}])

point_chart = dashboard.Chart3D(row_index=0, column_index=1, title="3D Earthquake Visualization")
point_series = point_chart.add_point_series(render_2d=False, individual_lookup_values_enabled=True)

for year in years:
    year_data = data[data['datetime'].dt.year == year]
    grid_mag = griddata((year_data['longitude'], year_data['latitude']), year_data['magnitudo'], (grid_lon, grid_lat), method='linear')
    surface_series.invalidate_height_map(grid_mag.tolist())
    
    point_series.clear()
    point_series.add([{'x': row['longitude'], 'y': row['latitude'], 'z': row['depth'], 'value': row['magnitudo']} for _, row in year_data.iterrows()])
    
    time.sleep(1)
Global-Earthquake-Analysis-Spatial-Distribution

Use Case:

  • Helps in identifying seismically active zones and their intensity over time.
  • Provides an understanding of how earthquake depth and magnitude correlate.
  • Useful for predicting potential high-risk seismic zones.

Treemap Chart: Global Earthquakes Analysis Magnitude by Continent

This treemap chart categorizes earthquake magnitudes by continent and country. Each box represents a country, color-coded based on its average earthquake magnitude.

Results & Interpretation:

  • Asia & America Have High Magnitudes:
    • Many Asian and American countries (red/orange) experience strong earthquakes (above 6.0).
    • Countries in the Pacific Ring of Fire dominate the high-magnitude regions.
  • Africa & Europe Show Lower Magnitudes:
    • European countries (green/yellow) generally have lower earthquake magnitudes.
    • Africa has mixed patterns, with some regions reaching 5.5-6.0 magnitudes.
  • Oceania & Antarctica Are Smaller Regions:
    • Oceania contains highly active earthquake regions, though some islands experience moderate activity.
    • Antarctica shows occasional seismic activity but remains mostly stable.
chart = lc.TreeMapChart(
    theme=lc.Themes.Dark,
    title="Earthquake Magnitude by Continent"
)

chart.set_data(treemap_data)

color = chart.set_node_coloring(
    steps=[
        {'value': 3.0, 'color': lc.Color('green')},
        {'value': 4.0, 'color': lc.Color('yellow')},
        {'value': 5.0, 'color': lc.Color('orange')},
        {'value': 6.0, 'color': lc.Color('red')},
        {'value': 7.0, 'color': lc.Color('darkred')}
    ]
)

legend = chart.add_legend()
legend.set_position(20, 20)
legend.set_margin(10)
legend.add(color)

chart.open()
Global-Earthquake-Analysis-Treemap

Use Case:

  • Helps seismologists identify high-risk continents based on average earthquake strength.
  • Supports disaster preparedness by highlighting vulnerable regions.
  • Useful for climate and geophysical studies of global seismic activity.

Future Earthquake Forecast (2024-2033)

This visualization presents earthquake forecast data from 2024 to 2033 using historical data and ARIMA modeling. It consists of:

  • Historical Data (1990-2023) in light blue.
  • Forecasted Data (2024-2033) as a projected trend.
  • Confidence Interval with lower and upper bounds to estimate possible variations.

Results and Interpretation

The historical data shows significant fluctuations in the number of earthquakes over time, with peaks around 2008 and 2020. The forecast suggests a stabilization in the number of earthquakes from 2024 onward, with a slight upward trend. The confidence bands (upper and lower bounds) indicate uncertainty, but the general trajectory suggests earthquake frequencies will not drastically decline or rise.

df['datetime'] = pd.to_datetime(df['date'], errors='coerce', utc=True)
df = df.dropna(subset=['datetime'])
df['year'] = df['datetime'].dt.year

yearly_counts = df['year'].value_counts().sort_index()

model = ARIMA(yearly_counts.values, order=(2, 1, 2)).fit()
forecast = model.forecast(steps=10)
smoothed_forecast = np.convolve(forecast, np.ones(3)/3, mode='valid')
forecasted_values = np.concatenate((forecast[:2], smoothed_forecast))

predicted_years = np.arange(2024, 2034)
lower_bound, upper_bound = forecasted_values * 0.9, forecasted_values * 1.1

chart = lc.ChartXY(title="Future Earthquake Forecast (2024-2033)", theme=lc.Themes.TurquoiseHexagon)

chart.add_point_line_series().set_name("Historical Data").add(x=yearly_counts.index, y=yearly_counts.values)
chart.add_point_line_series().set_name("Forecasted Data").add(x=predicted_years, y=forecasted_values)
chart.add_point_line_series().set_name("Lower Bound").add(x=predicted_years, y=lower_bound)
chart.add_point_line_series().set_name("Upper Bound").add(x=predicted_years, y=upper_bound)

chart.get_default_x_axis().set_title("Year")
chart.get_default_y_axis().set_title("Number of Earthquakes")
chart.open()
Global-Earthquake-Analysis-Forecast

Use Case

  • Seismic Risk Assessment: Helps predict future seismic activity for preparedness.
  • Disaster Planning: Allows authorities to allocate resources for earthquake-prone regions.
  • Scientific Research: Useful for analyzing long-term seismic trends and the impact of geological shifts.

Conclusion

This study provides a comprehensive visualization of global earthquake patterns using LightningChart Python, uncovering trends in frequency, magnitude, depth, and geographic distribution.

Temporal analysis highlights variations in earthquake frequency over time, while geospatial charts confirm high seismic activity along tectonic plate boundaries, particularly in the Pacific Ring of Fire.

Scatter plots reveal that shallower earthquakes tend to be more destructive, and comparisons between tsunami-related and non-tsunami earthquakes indicate that stronger quakes are more likely to trigger tsunamis.

Additionally, the ARIMA-based forecasting model offers insights into future seismic activity, aiding in disaster preparedness. By integrating high-performance visual analytics, this project enhances our understanding of seismic behavior, contributing to better risk assessment and early warning strategies.

Continue learning with LightningChart