# How to plot a cross-section map in PYGMT?

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-plot-a-cross-section-map-in-pygmt/3576>\
**Category:** PyGMT Q&A\
**Created:** [December 31, 2022, 8:30am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-a-cross-section-map-in-pygmt/3576 "2022-12-31T08:30:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adnan](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Adnan](https://forum.generic-mapping-tools.org/u/Adnan)\
**Post date:** [December 31, 2022, 8:30am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-a-cross-section-map-in-pygmt/3576/1 "2022-12-31T08:30:38Z")

</div>

Hi everyone,

I am struggling with the cross-section plot of earthquakes along with the FMS.

Here is my script:  
May someone suggest me how can I fix this.

Thank you!

Data and expected results are attached here.

```python
import pygmt
import numpy as np
import pandas as pd
names = ["lat", "long", "depth", "Mag"]
df = pd.read_txt('USGS.txt',sep=',',names=names)
lons = df['long']
lats = df['lat']
mag=df['Mag']
dep=df['depth']

minlon, maxlon = 68, 75
minlat, maxlat = 33, 39
region=[minlon, maxlon, minlat, maxlat]
grid = pygmt.datasets.load_earth_relief(resolution="30s", region=region)
fig = pygmt.Figure()
fig.grdimage(grid=grid,region=region,projection='M4i',shading=True,frame=True, cmap="grayC")
pygmt.makecpt(cmap="turbo", series='0/400/100',continuous=True)
#fig.coast(shorelines=True,frame=True, map_scale='jBL+w100k+o0.6c/0.6c+f')
fig.plot(x=lons, y=lats, size=0.02*(1.6**mag), style="cc", color= dep, pen="black", cmap=True)
fig.colorbar(frame='+l"Depth (km)"')
fig.plot(x=[71.5, 70], y=[35, 37], projection="M", pen=2)
fig.text(x=71.15, y=35.15, text="A", font="12,Helvetica")
fig.text(x=70.15, y=37.15, text="B", font="12,Helvetica")

#pygmt.project(output="cross.dat", x=lons,y=lats,z=dep,center="71.5/35",endpoint="70/37",width="-100/100")

fig.show()

```

 ![Screenshot 2022-12-31 at 4.25.04 PM](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f2a4029604d8a591e33dfeeca9707d707018ba1b.jpeg)

I am looking for a similar result along with the FMS.

 ![Screenshot 2022-12-31 at 4.29.28 PM](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/1/1dde22d0c2d5b75a31af4dcce76c518cf73313b5.jpeg)

Three cross-section lines with three subplots in lower panel.

Data is also attached here:

Thank you!

[Potassic.txt](https://forum.generic-mapping-tools.org/uploads/short-url/wwsQdkZ9dBMXVkagZgZK2uwKWB8.txt) (26.4 KB)

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [December 31, 2022, 1:16pm UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-a-cross-section-map-in-pygmt/3576/2 "2022-12-31T13:16:05Z")

</div>

Hi Adnan!!

How would like to make the cross-section? 1. Depth vs Long (or Lat)? or 2. Depth vs Distance (like in the attached figures)?

I think that 2 is better. And, in this case you first need to project them into the cross-section (with project).

---

<div class="post-metadata">

**Author:** ![Adnan](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Adnan](https://forum.generic-mapping-tools.org/u/Adnan)\
**Post date:** [January 1, 2023, 6:14am UTC](https://forum.generic-mapping-tools.org/t/how-to-plot-a-cross-section-map-in-pygmt/3576/3 "2023-01-01T06:14:08Z")

</div>

@Esteban82 Thanks, Yes, depth vs distance or depth verse latitude, both are ok, I think.  
Here is the more clear figure of the output I am looking for.

 ![Screenshot 2023-01-01 at 3.55.01 PM](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/4/4fe410e46abd1a6d75dc189ca192592889cb8360.jpeg)
