Inverted Grayscale Colormap

How do I create a custom colormap that’s a continuous gradient between two colors?

For example, I want the bottom of the scale to be a mid-gray color and the top to be black.

This seems like it might work.
gmt makecpt -C80/80/80,0/0/0 -T0/1 -Fr -N

0	80/80/80	1	0/0/0	L

However, when I do something like this is pygmt, it acts like no colormap is employed.
pygmt.makecpt(color_model='r',cmap='80/80/80,0/0/0',series='0/1',no_bg=True)

I’m trying to show “mountains” by filtering relief data by elevation and then drawing it with something like:

fig.grdimage(grid=grid, projection=projection, frame="a", cmap=True)

If I use one of the standard colormaps (e.g. ‘geo’, ‘gray’, …) it does what I’d expect (though using a colormap I don’t want).
I probably don’t understand colormap creation properly, but I’m not sure what I’m doing wrong. How can I accomplish this?

Hi,
This is a PyGMT question. Please use the PyGMT channel to ask them.

i think it’s not, pygmt.makecpt() generates an identical .cpt file using H/output option.

more likely

don’t understand colormap creation properly

e.g. -T0/1 specifies range of altitudes/Z coordinate of 0 to1 (meters or whatever topicstarter’s data is)
for altitudes the range of 0 to 1 is not gonna work, unless the user knows exactly what he/she is doing.

1 Like

Hello @mojomojomojo,

welcome to the GMT forum :slightly_smiling_face: !

I tried your PyGMT code line for setting up the colormap and in principle it looks good for me:

import pygmt

size = 5

fig = pygmt.Figure()
fig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=0)

pygmt.makecpt(color_model="r", cmap="80/80/80,0/0/0", series="0/1", no_bg=True)
fig.colorbar(cmap=True, position="JMC", frame=True)

fig.show()

Some ideas:

  • Did you set up your colormap within / after calling fig = pygmt.Figure()? This is required to use cmap=True with the plotting methods.
  • You are using quite similar gray hues, so the gradient is very weak and difficult to see.
  • The value range of the colormap is 0 to 1. Maybe this is not the value range of your relief data.
import pygmt

size = 5

fig = pygmt.Figure()
fig.basemap(region=[-size, size, -size, size], projection=f"X{size}c", frame=0)

pygmt.makecpt(cmap="gray90,gray10", series=[0, 1000])
# pygmt.makecpt(cmap="gray90,gray10", series=[0, 1000], reverse=True)

fig.colorbar(cmap=True, position="JMC", frame=True)

fig.show()

1 Like

Does gridimage have to apply a color to every point? What can I do to the relief data in order to display “nothing” for a given position? (I’m trying to create “layers” for this map.)

You can set altitude at a given position to NaN and request NaN transparency from grdimage

1 Like