Plot focal mechanisem offset in Pygmt

Hello Guys
I have Problem about plot focal mechanisem offset in Pygmt:
my script python below:

######################
import pygmt
import pandas as pd

#Read Data
data = pd.read_csv(‘eq_data_sulut-focmech2.csv’)
#Region
minlon, maxlon = 117.4,130
minlat, maxlat = -4.0,8
region = [minlon,maxlon,minlat,maxlat]

#Plot coast

fig = pygmt.Figure()
fig.coast(region=region,
projection=‘M10c’,
frame = ‘ag’,
shorelines=‘0.25p,black’,
land=‘grey’,
water=‘lightblue’)

#Plot Data Focal Mechanisme
fig.meca(spec=data,
convention=‘aki’,
scale =‘0.3c’,
offset=True,
frame = True)

#Convert file to PNG
fig.savefig (“focmech_sulut2.png”, crop=True, dpi=500, transparent=True)

That’s a known issue with pygmt.meca for PyGMT <=v0.7.0. Fortunately, we have fixed the issue in the master branch, so you can install the master branch of PyGMT and see if it works for you.

Hello sir Seisman
thanks a lot for your valuable comment.
How I install the master branch of pygmt??

You can try this:

pip install --pre --extra-index-url https://test.pypi.org/simple/ pygmt

Hello sir Seisman
I already upgrade my Pygmt version to 0.7 and install master branch of PyGMT based on your instruction. However, when I run my script for alternative plot focal mechanisme in order not overlaping , it’s not going to work.

This below is my script:
###############
import pygmt
import pandas as pd

#Read Data
data = pd.read_csv(‘eq_data_sulut-focmech2.csv’)
#Region
minlon, maxlon = 117,131
minlat, maxlat = -4.0,8
region = [minlon,maxlon,minlat,maxlat]

#Plot coast
fig = pygmt.Figure()
fig.coast(region=region,
projection=‘M10c’,
frame = ‘ag’,
shorelines=‘0.25p,black’,
land=‘grey’,
water=‘lightblue’)

#make color ramp for depth
pygmt.makecpt(cmap=“jet”, reverse = True,series=[data.depth.min(),data.depth.max()])

#Plot erathquake based on depth
fig.plot(x = data.longitude,
y = data.latitude,
size = 0.002 * (2**data.magnitude),
pen =‘faint’,
style =‘c0.2’,
color =data.depth,
cmap = True)

#Plot colorbar
fig.colorbar(frame=‘af+l"Depth (km)"’)

#Plot Data Focal Mechanisme
fig.meca(spec=data,
convention=‘aki’,
scale =‘0.3c’,
C = True, #panel
plot_longitude=True,
plot_latitude=True,
frame = True)

#Convert file to PNG
fig.savefig (“focmech_sulut2.png”, crop=True, dpi=500, transparent=True)

data

Try adding offset=True to your meca function.

Hello sir Seisman
I change my script using offset but the result still same before.
I run this script using pycharm.

########
import pygmt
import pandas as pd

#Read Data
data = pd.read_csv(‘eq_data_sulut-focmech2.csv’)
#Region
minlon, maxlon = 117,131
minlat, maxlat = -4.0,8
region = [minlon,maxlon,minlat,maxlat]

#Plot coast
fig = pygmt.Figure()
fig.coast(region=region,
projection=‘M10c’,
frame = ‘ag’,
shorelines=‘0.25p,black’,
land=‘grey’,
water=‘lightblue’)

#make color ramp for depth
pygmt.makecpt(cmap=“jet”, reverse = True,series=[data.depth.min(),data.depth.max()])

#Plot earthquake based on depth
fig.plot(x = data.longitude,
y = data.latitude,
size = 0.002 * (2**data.magnitude),
pen =‘faint’,
style =‘c’,
color =data.depth,
cmap = True)

#Plot colorbar
fig.colorbar(frame=‘af+l"Depth (km)"’)

#Plot Data Focal Mechanisme
fig.meca(spec=data,
offset=True,
convention=‘aki’,
scale =‘0.3c’,
C = True, #panel
frame = True)

#Convert file to PNG
fig.savefig (“focmech_sulut3.png”, crop=True, dpi=500, transparent=True)

Please upload you CSV data file, so that I can give it a try.

Hai sir Seisman
Link below my csv data for plot focal mechanisme data in Pygmt:
Thanks a lot for your response

Hai Sir Seisman
in terms of my previously problem, Now I have already fixed it.
Thanks in advance for your valuable comment.

Scritp bellow it’s working.
###########################################

import pygmt
import pandas as pd

#Read Data
data = pd.read_csv(‘eq_data_sulut-focmech2.csv’)
#Region
minlon, maxlon = 113,131.5 #defenisikan batas geografis longitude
minlat, maxlat = -4.0,10#defenisikan batas geografis latitude
region = [minlon,maxlon,minlat,maxlat]

#Plot coast
fig = pygmt.Figure()
fig.coast(region=region,
projection=‘M10c’,
frame = ‘ag’,
shorelines=‘0.25p,black’,
land=‘grey’,
water=‘lightblue’)

#Plot arrow dan scale bar
fig.basemap(rose=“jTL+w1.3+lo,E,S,N+o-0.00001c/5.5c”,
map_scale=“jBL+w500k+o4.0c/0.36c+f”)

color ramp untuk for Earthquake Depth
pygmt.makecpt(cmap=“jet”, reverse = True,series=[data.depth.min(),data.depth.max()])

#Plot Earthquake based on Depth
fig.plot(x = data.longitude,
y = data.latitude,
size = 0.002 * (2**data.magnitude),
pen =‘faint’,
style =‘c’,
color =data.depth,
cmap = True)

#Plot depth colorbar
fig.colorbar(frame=‘af+l"Depth (km)"’)

#plot Magnitude Legend
fig.legend(spec=‘magnitude_leg.txt’,
position=‘JTL+jTL+o0.1c+w1.6/4.0’,
box=‘+glavender’)

#Plot Data Focal Mechanisme
fig.meca(spec=‘focal_data.txt’,
convention=‘aki’,
scale =‘0.3c’,
C = True, #panel
offset = True)

#Adding Inset of Map
with fig.inset(position=“jBr+w3c”):
fig.coast(region=[95,141,-11.3,8.8],
projection=‘M3c’,
land=“gray”,
borders=[1,3],
shorelines=“1/thin”,
water=“white”,
dcw=“ID+gred”)

#Convert file ke PNG
fig.savefig (“focmech_sulut5.png”, crop=True, dpi=300, transparent=True)