Custom CPT

Hey everyone,

I am new to pygmt (awesome job guys!) and I am trying to generate a global distribution map of sediment thicknesses in the ocean (based on the globsed grid published by Straume et al., 2019).

I have the following code so far (with the grid stored as the ‘globsed_grid’ var) :

fig = pygmt.Figure()
cmap_range = "0/10000/10"
fig.grdimage(globsed_grid, region='d', projection='N12c', nan_transparent=True, cmap = pygmt.makecpt(cmap='vik', series=cmap_range))
fig.colorbar(frame=['x+l"Sediment thickness (m)"'])

fig.show()

I would like to force the color changes at non linearly spaced values, (eg. [0, 100, 200, 300, 400, 500, 1000, 3000, 6000, 8000, 10000].

It seems that this is feasable with gmt (cf Make CPT with custom intervals and colors), but what about PyGMT?

Many thanks for your help in advance

1 Like

Hello @sjgetienne,

welcome to the GMT forum. Pleased to hear, that you find PyGMT useful for your work :slightly_smiling_face: .

Your question has some overlap with the question at: Customized annotation for colorbar - PyGMT
Maybe the code examples posted there can severe as an orientation for you?

Yeah many thanks, some good leads in this post that came just after mine!
I was hoping to modify an existing cpt (eg those of fabio crameri) but it seems that creating a fully new cpt is mandatory…
Cheers,
Samuel

Here’s some kind of solution.

I exported a .cpt file with a custom range and step but from a master cpt (‘roma’) using the pygmt.makecpt() function. Then I manually modified this .cpt file with a text editor to edit the values of the color bins :


cmap_range = "0/10000/500"  # selecting a range and step 
pygmt.makecpt(cmap='roma', reverse=True, series=cmap_range, output='custom_roma.cpt') # exporting the custom .cpt file
 

Then I just passed this custom cpt file to the cmap param of the .grdimage() function :


fig=pygmt.Figure()
fig.grdimage(globsed_grid, region='d', projection='N12c', cmap = 'custom_roma.cpt')
fig.colorbar(frame=['x+l"Sediment thickness (m)"'])
fig.show()

Hope this will help others!
Sam

1 Like

Forgive if I am not getting it, but were you able to solve the original query you had. That is to create cmap for levels “0, 100, 200, 300, 400, 500, 1000, 3000, 6000, 8000, 10000”… levels of unequal intervals.
I could reproduce one with equal interval but not one with unequal interval.