Plotting Earthquake Focus#

Pure Geophysics Seismology

import plotly.graph_objs as go
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.express as px

init_notebook_mode (connected = True)
import numpy as np
import pandas as pd

1. Import Earthquake data#

Create a dataset which contains longitude, latitude, depth, and magnitude of each event. The study area of this practice is New Zealand.

df = pd.read_excel('data/meca_all.xlsx')
df.head()
Longitude Latitude Depth(km) Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 Unnamed: 10 Unnamed: 11 Unnamed: 12 Unnamed: 13 Mag Unnamed: 15 Unnamed: 16 Unnamed: 17 Lat
0 182.31 -30.00 -44 6.98 -0.13 -6.84 1.35 2.57 -4.01 23 X Y 090384A 7.500000e+23 5.2 NaN -177.69 44 -30
1 183.30 -30.00 -14 1.27 -0.05 -1.22 0.33 1.28 -0.38 25 X Y 200810050912A 1.800000e+25 6.1 NaN -176.70 14 -30
2 183.19 -30.01 -22 1.05 0.09 -1.13 -0.21 0.01 -0.54 24 X Y 052081B 1.100000e+24 5.3 NaN -176.81 22 -30
3 182.84 -30.01 -17 0.95 -0.13 -0.82 -0.06 1.22 -0.35 24 X Y 051304F 1.600000e+24 5.4 NaN -177.16 17 -30
4 183.57 -30.01 -35 1.92 -0.16 -1.76 -0.32 -0.12 0.19 24 X Y 200603311543A 2.000000e+24 5.5 NaN -176.43 35 -30

2. Create a 3D plot of focus#

Hover to see the details of each event. Zoom in and rotate the diagram to suit yourself.

table = df.loc[:,['Longitude','Latitude','Depth(km)','Mag']]
plot_scatter = go.Scatter3d(
    x = table['Longitude'],
    y = table['Latitude'],
    z = table['Depth(km)'],
    mode = 'markers',
    marker = dict(
        size = 5,
        cmax = 8,
        cmin = 4.5,
        color = table['Mag'],
        colorbar = dict(title = 'Magnitude'),
        colorscale = 'matter'
    )
    #title = 'Earthquake focal mechanism data from 1976 to 2020',
    #labels = {'Longitude': 'Longitude'},
    #labels = {'Latitude': 'Latitude'},
    #labels = {'Depth(km)': 'Depth(km)'},
)

plotdata = [plot_scatter]
layout = go.Layout(
    margin = dict(
        l = 0,
        r = 0,
        b = 0,
        t = 0,
    )
)
fig = go.Figure()
fig.update_layout(scene = dict(
    xaxis_title='Longitude',
    yaxis_title='Latitude',
    zaxis_title='Depth'),
    width=700,
    margin=dict(r=0, b=0, l=0, t=0))


fig = go.Figure(data = plotdata, layout = layout)
iplot(fig, filename = 'meca3D')
import pandas as pd  # (version 1.0.0)
import plotly.express as px  # (version 4.7.0)
import plotly.io as pio
import numpy as np
import plotly.graph_objects as go

Latitude-migrated 3D focus plot#

You could see the subducting plate changes dip direction from westward to eastward down the latitude.

import plotly.express as px
df = pd.read_excel('data/meca_all.xlsx')
px.scatter_3d(df, x="Longitude", y="Latitude", z="Depth(km)", animation_frame="Lat", 
           size="Mag", color="Mag", size_max=15, range_x=[160,184], range_y=[-50,-30], range_z=[-600,0])

3. Create a Latitude-migrated focus cross section plot#

You could see the subducting plate changes dip direction from westward to eastward down the latitude.

import plotly.express as px
df = pd.read_excel('data/meca_all.xlsx')
px.scatter(df, x="Longitude", y="Depth(km)", animation_frame="Lat", 
           size="Mag", color="Mag", size_max=10, range_x=[160,184], range_y=[-600,0])