Create custom colormap?

In some matplotlib code I have, I have created a custom colormap using the matplotlib LinearSegmentedColormap and a list of red, green, blue, alpha values at various stops between 0 and 1. I would now like to use this same colormap in pygmt, but all I have been able to find so far is the pygmt.makecpt function which from what I can tell only allows you to modify one of the standard colormaps, not create a new custom one.

As such, is there a way to either a) convert the matplotlib colormap into one that will work with pygmt, or b) create from scratch a new colormap for pygmt using the colors/stops I have?


In GMT you can work from saved .cpt files directly. Such text file contains a list of colour gradients, defined as two bounding RGB colours and a range of values (e.g. You can use the file directly or adapt the value range to your data with makecpt.