Draw the trace of a fault using PyGMT

Hi all,
I’m quite new on pygmt, I’m trying to plot the trace of a fault on the surface by using this code

figure.plot(x=np.array([4,8]), y=np.array([-10,10]), pen="1.25p", style= "f1c/0.3c+l+t", color="red3")

but nothing happened, any tips please !!!

Thanks in advance !!!

Hello @geoexplo,

for me your code snippet looks already quite good. Maybe only the pen color (color of the line) is missing, i.e. you have to change

pen="1.25p"

to

pen="1.25p,black" 

or any other color you want.


I completed your code snippet to a full script:

import pygmt
import numpy as np


fig = pygmt.Figure()

fig.basemap(
    region=[0, 10, -10,10],
    projection="X10c",
    frame="afg",
)

fig.plot(
    x=np.array([4,8]),
    y=np.array([-10,10]),
    style="f1c/0.3c+l+t",
    color="red3",
    # pen="1.5p",  # <<< maybe color of basic line is missing?
    pen="1.5p,black",  
)

fig.show()
# fig.savefig(fname="pygmt_fault.png",)

output figure:


There is further a PyGMT gallery example explaining how to draw Line fronts — PyGMT.
For a more detailed help, please post your own complete script :slight_smile: .

1 Like

Thanks for you answer ! I have another question : is it possible to plot multiple fault traces by using a text file for example?

Do you mean like multi-segment files?

I mean by using PyGMT :blush:

I think that also works.

As @Esteban82 mentioned, you have to provid a so-called multi-segment file. For details, please have a look at the link above ponting to the related GMT documentation, which also works for PyGMT :slight_smile:.

In principle you can draw different faults using the unique identifier > to separate the different faults from each other in the file. Please place the file gmt_faults_multi_segment_same.txt (271 Bytes) in your working directory.

Example script

import pygmt

fig = pygmt.Figure()

fig.basemap(
    region=[0, 10, 0,10],
    projection="X10c",
    frame="afg",
)

fig.plot(
    data="gmt_faults_multi_segment_same.txt",
    style="f1c/0.3c+l+t",
    color="red3",
    pen="1p,black",
)

fig.show()
# fig.savefig(fname="pygmt_faults_multi_segment_same.png",)

Output figure