I want to give symbols to my earthquake data like size to magnitude and color to depth but im unable can someone help me

filtered_data_gmt.txt (100.0 KB)
this is the file.

import numpy as np
import pygmt


fig = pygmt.Figure()

# CPT (adjust to your depth/magnitude range if needed)
pygmt.makecpt(cmap="red,green,blue", series="0/300/10", output="quakes.cpt")

# --------------------
# 1) MAP PANEL
# --------------------
fig.coast(
    region=[127.6, 134.4, 30, 34.4],
    projection="M4i",
    frame=["xa1g1", "ya1g1", '+t"Kyushu"'],
    land="lightbrown",
    shorelines="0.25p",
)

fig.basemap(
    map_scale="jBR+w200k+o0.5c/0.5c+f"
)

fig.plot(
    data="filtered_data_gmt.txt",
    style="c0.15c",
    pen="faint",
    cmap="quakes.cpt",
)

# --------------------
# 2) AUTO PROFILE LINE (PCA, NO EXTENSION) + PROJECT
# --------------------
xy = np.loadtxt("filtered_data_gmt.txt", usecols=(0, 1), skiprows=1)

lon = xy[:, 0]
lat = xy[:, 1]

X = np.column_stack([lon, lat])
X0 = X - X.mean(axis=0)

C = np.cov(X0.T)
eigvals, eigvecs = np.linalg.eig(C)
v = eigvecs[:, np.argmax(eigvals)]

# Keep direction consistent
if v[0] < 0:
    v = -v

t = X0 @ v
tmin, tmax = t.min(), t.max()

# A and B exactly at data limits (NO extension)
A = X.mean(axis=0) + tmin * v
B = X.mean(axis=0) + tmax * v

# Plot the profile line in BLACK
fig.plot(
    x=[A[0], B[0]],
    y=[A[1], B[1]],
    pen="2p,black",
)

# Project earthquakes onto the profile
pygmt.project(
    data="filtered_data_gmt.txt",
    unit=True,
    center=[float(A[0]), float(A[1])],
    endpoint=[float(B[0]), float(B[1])],
    convention="pz",
    width=[-100, 100],
    outfile="cross.dat",
    output_type="file",
)

# --------------------
# 3) CROSS-SECTION PANEL
# --------------------
fig.shift_origin(yshift="-8c")

fig.basemap(
    projection="X10c/-6c",
    region=[0, 80, 0, 50],
    frame=[
        'xafg10+l"Distance (km)"',
        'yafg10+l"Depth (km)"',
        "WSen",
    ],
)

fig.plot(
    data="cross.dat",
    style="c0.2c",
    pen="0.5p,black",
    fill="red",
)

# --------------------
# 4) OUTPUT
# --------------------
fig.savefig("kyushu_cross_section.pdf")
fig.show()

Hi @parbuss2-hue,

I just formatted your script as code. You can do this by placing three backticks in the line before and after the block with the script:

```
your script formatted as code
```

For the size coding (magnitude):
If you want to use a quantity, there should be no size given via the style parameter: style=c0.15cstyle="cc". Probably you need to scale the magnitude values before plotting.

For the color coding (depth):
Based on your data, all earthquakes are shallower than 20 km. Your colormap covers the range 0-300 km using three different colors. So all points are plotted in the first color, in your case red.

im using GMT for first time in my life during my internship and i have windows will you help me adjusting my code ? will you add it in my code ?

Try what everyone is doing these days. Ask an LLM (I strongly advise using Claude.ai) to write you the script. Be specific on the things you want in your figure.

@parbuss2-hue, I agree learning GMT can be overwhelming at the beginning, but with the Python (and Julia) wrappers, things get much easier.

Besides asking a LLM to write you the script (I guess you got the script and should adjust it for your task and data), you can go the old-school way: The PyGMT tutorial Plotting data points — PyGMT explains how to create the type of map you want.

Hey! The issue is that you’re using a fixed size in style="c0.15c". To get PyGMT to pull both size and color from your file, you need to change that to style="cc".

That second “c” tells the tool to look at your data columns for the symbol diameter. Just a heads-up: if your magnitude is 5.0, style="cc" will draw a 5 cm circle, which is huge. You’ll probably want to scale that column (like mag \times 0.1) before plotting so the symbols stay at a reasonable size.

Your map plot should look like this:

fig.plot(
    data="filtered_data_gmt.txt",
    style="cc",  # This reads the size from your data
    cmap=True,   # This reads the color from your data
    pen="faint"
)

For the cross-section, double-check your pygmt.project output. If cross.dat only has distance and depth, the final fig.plot won’t have the magnitude column it needs to scale the symbols. Make sure you’re passing that extra column through.

Hope that helps!