Coloring symbols with cpt PyGMT

Hi all, I am having trouble filling in symbols that represent seismic stations based on a different variable using PyGMT. I have seen other threads, but none of them seem to work.

I am trying to plot seismic stations on a map, and each station should be colored depending on the value of calculated Moment pertaining to the seismic station. I am using a Pandas dataframe , stations_df, to store the information, and it looks like this:
Screen Shot 2023-06-13 at 2.22.02 PM

Below is the code that I am using:

import pandas as pd
import pygmt

stations_df = pd.read_csv('gmtstations.dat')

overall_region = [-92,-68,25,47]

mi = stations_df.Moment.min()
ma = stations_df.Moment.max()

pygmt.makecpt(cmap='seis', continuous=True, series=[mi,ma,0.1e+24])

proj = 'M20c'
fig = pygmt.Figure() #Start the figure

fig.basemap(region=overall_region, projection=proj, frame=True)

fig.coast(region=overall_region, projection=proj, land='lightgrey', transparency =70, resolution='f')
fig.coast(projection=proj, resolution='f', borders = 'a', shorelines='0.2')


fig.plot(projection=proj, x=stations_df.LON, y=stations_df.LAT, fill=stations_df.Moment, cmap=True, style='t0.4', pen='black')

fig.show()

The figure that it creates is the following:

The code runs, but all the stations plot black instead of using the color palette that I assigned. I thought initially that the values of moment were too big, so I normalized all the moment values, but that still colored all the stations black. Is there something wrong with the way that I am calling the fill color/map or creating the color palette, or does anyone know where the issue could be? Thank you for your help!

Hello @Lbmartinetti,

does setting up the colormap after setting up the Figure object help?

# ...
proj = 'M20c'

fig = pygmt.Figure() #Start the figure

# Set up colormap after setting up the figure object
pygmt.makecpt(cmap='seis', continuous=True, series=[mi,ma,0.1e+24])
# ...

Hi @yvonnefroehlich , I tried this and it is still plotting the stations as black. I could provide some files if that is helpful.

Hallo @Lbmartinetti,

providing your data, i.e. the file ‘gmtstations.dat’ would be very helpful :slightly_smiling_face:. Thanks!

I have attached the gmtstations.dat file to this thread. Thanks for your help!

gmtstations.dat (6.8 KB)

Thanks for providing your data @Lbmartinetti.

If I modify your code like suggested above:

import pandas as pd
import pygmt

stations_df = pd.read_csv('gmtstations.dat')

overall_region = [-92,-68,25,47]

mi = stations_df.Moment.min()
ma = stations_df.Moment.max()

# Move creation of colormap down and set it up after setting up 
# the Figure object
# pygmt.makecpt(cmap='seis', continuous=True, series=[mi,ma,0.1e+24])

proj = 'M20c'

fig = pygmt.Figure() #Start the figure

# Set up colormap after starting the figure
pygmt.makecpt(cmap='seis', continuous=True, series=[mi,ma,0.1e+24])

fig.basemap(region=overall_region, projection=proj, frame=True)

fig.coast(region=overall_region, projection=proj, land='lightgrey', transparency =70, resolution='f')
fig.coast(projection=proj, resolution='f', borders = 'a', shorelines='0.2')


fig.plot(projection=proj, x=stations_df.LON, y=stations_df.LAT, fill=stations_df.Moment, cmap=True, style='t0.4', pen='black')

fig.show()
# fig.savefig(fname="usa_triangels_pandas_cpt.png")

I get this output figure:

@yvonnefroehlich I copied and pasted the code that you provided and it is still making the triangles black. The issue could be in my computer. Would you recommend removing and reinstalling PyGMT on my computer?

Hm. Currently, I have unfortunately no idea what is going wrong :slightly_frowning_face: .

Can you please run

import pygmt
pygmt.show_versions()

and post the output.

Maybe you can try the PyGMT tutorial Plotting data points — PyGMT. It is in principle what you want to do. Would be interesting to see, if the same problem occurs.

Hi, after running pygmt.show_versions() I get the following:

PyGMT information:
version: v0.9.0
System information:
python: 3.11.3 | packaged by conda-forge | (main, Apr 6 2023, 09:05:00) [Clang 14.0.6 ]
executable: /Users/lmartinetti/anaconda3/envs/research/bin/python
machine: macOS-12.6.6-x86_64-i386-64bit
Dependency information:
numpy: 1.24.3
pandas: 1.5.3
xarray: 2022.11.0
netCDF4: 1.6.3
packaging: 23.0
contextily: None
geopandas: 0.13.0
ghostscript: 9.54.0
GMT library information:
binary version: 6.4.0
cores: 8
grid layout: rows
image layout:
library path: /Users/lmartinetti/anaconda3/envs/research/lib/libgmt.dylib
padding: 2
plugin dir: /Users/lmartinetti/anaconda3/envs/research/lib/gmt/plugins
share dir: /Users/lmartinetti/anaconda3/envs/research/share/gmt
version: 6.4.0