Hello everyone!
Thanks for taking your time to read me.
I’m working on my PhD, and part of the work is to make a lot of maps. I’m used to make them with softwares such as qgis, arcgis and then with codes using pythong and matlab.
The thing is that my director asked me to make maps with GMT and at the moment and all the work i have to do, it’s been quite hard for me to take the hung on GMT and it’s format, so when i found out about PYGMT it was amazing.
I have been able to make most of the maps, but now im kinda stuck plotting velocity vectors on pygmt.
That’s why im making this post, in order to see if you can help me out.
So, for starters, i have some vectors that go past the map limits, and i know that gmt allows vectors to be plotted outside the map border, but i haven’t been able to find how using pygmt.
ChatGPT says that i should use
pygmt.config(MAP_VECTOR_CLIP=“off”)
But it doesn’t work.
The next part is, that i was able to plot my vectors, but i haven’t been able to plot the error circles.
i attached the picture that he sent me as reference of a map my director did using gmt, im trying to make something like that.
### Plot displacement vectors
#Cargar datos
data = pd.read_csv(r"D:/PYGMT/docs_dm/geodata.csv")
# Convert lists to arrays
# Convert to numeric type
data['Longitude'] = pd.to_numeric(data['Longitude'], errors='coerce')
data['Latitude'] = pd.to_numeric(data['Latitude'], errors='coerce')
data['Value3'] = pd.to_numeric(data['Value3'], errors='coerce')
data['Error3'] = pd.to_numeric(data['Error3'], errors='coerce')
# plot points and vectors
for index, row in data.iterrows():
if pd.notna(row['Longitude']) and pd.notna(row['Latitude']) and pd.notna(row['Value3']):
# Plot points
fig.plot(x=row['Longitude'],
y=row['Latitude'],
style='c0.2c',
fill='black',
pen='black',
region=region,
projection=projection2,
frame=frame3)
# Calculate length and direction of vector
length = row['Value3'] * 0.1 # 0.05c por cada unidad de Value3
angle = 0 if row['Value3'] >= 0 else 180
# plot vector
fig.plot(x=row['Longitude'],
y=row['Latitude'],
direction=[[angle], [abs(length)]],
style='V0.2c+e+h0.5',
pen='1p,black',
region=region,
projection=projection2,
frame=frame3)
# plot error circles
y_position_with_error = row['Latitude'] + (length if row['Value3'] >= 0 else -length)
fig.plot(
x=row['Longitude'],
y=y_position_with_error,
style='c0.3c',
size=row['Error3'] * 10
pen='1p,black',
region=region,
projection=projection2,
frame=frame3)
This is my frankenstein, sorry if it’s not that great, it0s what i have come up with so far.
Everything works until i get to the circles.
Also, i just remembered i’m trying to interpolate this data, which works by itself, but it looks pixelated, so im trying to see if i can make it to be interpolated with a cubic interpolation or similar
#Plot grid uplift
fig.grdimage(grid=r"D:/PYGMT/docs_dm/HRC_STOTEN_intU_upd.grd",
cmap="./interseismic.cpt",
nan_transparent=True,
region=region,
projection=projection2,
transparency=50,
frame=frame3)
Thanks for any comment in advance, cheers!