Hello! I want to define the color of my beach balls according to the depth they have (and also to show that on the colorbar). How do I do it? There’s no a “fill” parameter as with figure.plot(). Thanks!
Here’s the plot part my code so far:
fig = pygmt.Figure()
# Create a colormap for depth values
pygmt.makecpt(cmap="jet", series=[df['depth'].min(), df['depth'].max()])
# Plot the topography and coordinate grid
fig.grdimage('@earth_relief_01m', region=region, projection='D0/-70/-90/-49/12c', cmap='geo')
fig.basemap(region=region, projection='D-0/70/-90/-49/12c', frame=True)
#Plot focal mechanisms
fig.meca(
spec=df,
scale='0.5c',
projection='D0/-70/-90/-49/12c',
region=region,
cmap=True
)
# Add colorbar with label "Profundidad focal (km)"
fig.colorbar(frame=["x+lProfundidad focal (km)", "y+lm"])
fig.show()
Can you please provide the data you read into the pandas.DataFrame df. Please also report the values of the varaiable region. Currently, it is a bit difficult to figure out what is going wrong in detail.
Yes it is possible to color-code beachballs based on their hypocentral depths.
I feel the issue comes from having two colormaps:
one for the elevation of the grid: grdimage with “geo”
one for the hypocentral depth of the beachball: meca or makecpt with “jet”
You have to create the colormap for the hypocentral depth after calling grdimage. Otherwise, cmap=True used in meca will consider the colormap set up by grdimage.
import pygmt
import pandas as pd
# Read txt file into Dataframe
df = pd.read_csv("meca_mt.txt", delimiter="\t")
# Define stuy area
region = [-180, 180, -90, -50]
# Create figure object
fig = pygmt.Figure()
# Plot the topography and coordinate grid
# Please note, I reduced the resolution from "01m" to "10m" to make the code run faster
fig.grdimage('@earth_relief_10m', region=region, projection='D0/-70/-90/-49/12c', cmap='geo')
fig.basemap(region=region, projection='D-0/70/-90/-49/12c', frame=True)
# Create a colormap for depth values
# Create the colormap for the hypocentral depth after "grdimage"
# Otherwise "cmap=True" considers the colormap (here "geo") set up by "grdimage"
pygmt.makecpt(cmap="jet", series=[df['depth'].min(), df['depth'].max()])
# Plot focal mechanisms
fig.meca(
spec=df,
scale='0.5c',
projection='D0/-70/-90/-49/12c',
region=region,
cmap=True,
)
# Add colorbar with label "Profundidad focal (km)"
fig.colorbar(frame=["x+lProfundidad focal (km)", "y+lm"])
fig.show()
# fig.savefig(fname="meca_two_cpts.png")