I’ve been trying to plot vertical displacements on a bird’s eye view map, with positive measurements shown by up arrows and negative displacements.
One solution I thought of was to put two additional columns in my CSV file, ‘sty’ and ‘pen’, which would change depending on the value of the displacement. ‘Sty’ contains the actual formatting options for the style parameter in fig.plot while ‘pen’ contains the formatting options for the pen parameter in the same command. This is achieved by doing an if-else command inside Excel, so no worries about this. Then I will call each column to the corresponding parameter (i. e. fig.plot(x=df.x,y=df.y,style=df.sty,pen=df.pen).
However, GMT doesn’t accept multiple style and pen options in one command, so what I did was to make a loop where the pd.read_csv command will only read one line at a time and then proceed to the next line after reading and plotting the previous one. This actually worked except for the style parameter. It seems that it has a different way of reading the options from a variable. I know calling the variable for pen works (pen=df.pen) because I tried to use a constant set of parameters for style and the vectors were plotted. The colors of the arrows are red if the displacement is positive and blue if it’s not. However, the arrowheads were constant because I can only make it work with constant style parameters.
Can anyone please help me on this? Thanks.
The barebones script is as follows:
import pygmt
import numpy as np
import pandas as pd
fig = pygmt.Figure()
region = [120.448, 120.451, 22.874, 22.876]
projection="M15c"
fig.basemap(region=region, projection="M15c", frame=["WSrt","a0.001"],rose=["x5.5i/3i+w0.75i+l,,,N"],map_scale=["x5.3i/0.2i+w20e+l"])
dtype = {"lon":float,"lat":float,"azi":float,"mag":float,"sty":str,"pen":str}
df=pd.read_csv("./style.csv",names=['lon','lat','mag','azi','sty','pen'],dtype=dtype,header=0)
i=1
for i in range(len(df.index)):
xf=pd.read_csv("./style.csv",names=['lon','lat','azi','mag','sty','pen'],dtype=dtype,header=0,skiprows=i,nrows=1)
print(xf)
fig.plot(x=xf.lon,y=xf.lat,direction=[xf.mag,xf.azi],region=region,projection=projection,style=xf.sty,pen=xf.pen)
i = i+1
fig.show()
problem.dat (1.8 KB)