makecpt

Make GMT color palette tables

Synopsis

gmt makecpt [ -Atransparency[+a] ] [ -Ccpt ] [ -D[i|o] ] [ -E[nlevels] ] [ -F[R|r|h|c][+c[label]][+kkeys] ] [ -Gzlo/zhi ] [ -H ] [ -I[c][z] ] [ -M ] [ -N ] [ -Q ] [ -Smode ] [ -T[min/max/inc[+b|i|l|n]|file|list] ] [ -V[level] ] [ -W[w] ] [ -Z ] [ -bibinary ] [ -dinodata[+ccol] ] [ -hheaders ] [ -iflags ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

Description

makecpt is a module that will help you make static color palette tables (CPTs). In classic mode we write the CPT to standard output, while under modern mode we simply save the CPT as the current session CPT (but see -H). You define an equidistant set of contour intervals or pass your own z-table or list, and create a new CPT based on an existing master (dynamic) CPT. The resulting CPT can be reversed relative to the master cpt, and can be made continuous or discrete. For color tables beyond the current GMT offerings, visit cpt-city.

The CPT includes three additional colors beyond the range of z-values. These are the background color (B) assigned to values lower than the lowest z-value, the foreground color (F) assigned to values higher than the highest z-value, and the NaN color (N) painted wherever values are undefined.

If the master CPT includes B, F, and N entries, these will be copied into the new master file. If not, the parameters COLOR_BACKGROUND, COLOR_FOREGROUND, and COLOR_NAN from the gmt.conf file or the command line will be used. This default behavior can be overruled using the options -D, -M or -N.

The color model (RGB, HSV or CMYK) of the palette created by makecpt will be the same as specified in the header of the master CPT. When there is no COLOR_MODEL entry in the master CPT, the COLOR_MODEL specified in the gmt.conf file or on the command line will be used.

Required Arguments

None.

Optional Arguments

-Atransparency[+a]

Sets a constant level of transparency (0-100) for all color slices. Append +a to also affect the fore-, back-, and nan-colors [Default is no transparency, i.e., 0 (opaque)].

-C[[section/] master_cpt[+h[hinge]][+u|Uunit]|local_cpt|color1,color2[,color3,…]]

Name of an input CPT file. Generally, the input is one of the GMT master_cpt files (see Of Colors and Color Legends) and can be either addressed by master_cpt or section/master_cpt (without the .cpt extension). If given a master CPT with soft-hinges then you can enable the hinge at data value hinge [0] via +h, whereas for hard-hinge CPTs you can adjust the location of the hinge [0]. For any other master_cpt, you may convert their z-values from meter to another distance unit (append +Uunit) or from another unit to meter (append +uunit), with unit taken from e|f|k|M|n|u. One can also supply the file name of already custom made local_cpt file. Alternatively, give color1,color2[,color3,…] to build a linear continuous CPT from those colors automatically, where z starts at 0 and is incremented by one for each color. In this case colorn can be a r/g/b triplet, a color name, or an HTML hexadecimal color (e.g. #aabbcc).

-D[i|o]

Select the back- and foreground colors to match the colors for lowest and highest z-values in the output CPT [Default (-D or -Do) uses the colors specified in the master file, or those defined by the parameters COLOR_BACKGROUND, COLOR_FOREGROUND, and COLOR_NAN]. Append i to match the colors for the lowest and highest values in the input (instead of the output) CPT.

-E[nlevels]

Implies reading data table(s) from given command-line files or standard input. We use the last data column to determine the data range; use -i to select another column, and use -bi if your data table is native binary. This z-range information is used instead of providing the -T option. We create a linear color table by dividing the table data z-range into nlevels equidistant slices. If nlevels is not given it defaults to the number of levels in the chosen CPT.

-F[R|r|h|c][+c[label]][+kkeys]

Force output CPT to be written with r/g/b codes, gray-scale values or color name (R, default) or r/g/b codes only (r), or h-s-v codes (h), or c/m/y/k codes (c). Optionally or alternatively, append +c to write discrete palettes in categorical format. If label is appended then we create labels for each category to be used when the CPT is plotted. The label may be a comma-separated list of category names (you can skip a category by not giving a name), or give start[-], where we automatically build monotonically increasing labels from start (a single letter or an integer). Append - to build ranges start-start+1 instead. If the categorical CPT should have string keys instead of numerical entries then append +kkeys, where keys is either a file with one key per record or a single letter (e.g., D), then we build sequential letter keys (e.g., D, E, F, …) starting at that point. For comma-separated lists of keys, use -T instead. Note: If +cM is given and the number of categories is 12, then we automatically create a list of month names. Likewise, if +cD is given and the number of categories is 7 then we make a list of weekday names. The format of these labels will depend on the FORMAT_TIME_PRIMARY_MAP, GMT_LANGUAGE and possibly TIME_WEEK_START settings.

-Gzlo/zhi

Truncate the incoming CPT so that the lowest and highest z-levels are to zlo and zhi. If one of these equal NaN then we leave that end of the CPT alone. The truncation takes place before any resampling. See also Manipulating CPTs

-H

Modern mode only: Write the CPT to standard output as well [Default saves the CPT as the session current CPT]. Required for scripts used to make animations via movie and batch where we must pass named CPT files.

-I[c][z]

Append c [Default] to reverse the sense of color progression in the master CPT. Also exchanges the foreground and background colors, including those specified by the parameters COLOR_BACKGROUND and COLOR_FOREGROUND. Append z to reverse the sign of z-values in the color table. Note that this change of z-direction happens before -G and -T values are used so the latter much be compatible with the changed z-range. See also Manipulating CPTs

-M

Overrule background, foreground, and NaN colors specified in the master CPT with the values of the parameters COLOR_BACKGROUND, COLOR_FOREGROUND, and COLOR_NAN specified in the gmt.conf file or on the command line. When combined with -D, only COLOR_NAN is considered.

-N

Do not write out the background, foreground, and NaN-color fields [Default will write them].

-Q

For logarithmic interpolation scheme with input given as logarithms. Expects input z-values provided via -T to be log10(z), assigns colors, and writes out z.

-Smode

Determine a suitable range for the -T option from the input table(s) (or standard input). Choose from several types of range determinations: -Sr will use the data range min/max, -Sinc[+d] will use the data min/max but rounded to nearest inc (append +d to resample to a discrete CPT), -Sascl will make a symmetric range around the average (i.e., mean) and ±scl * sigma, -Smscl will make a symmetric range around the median and ±scl * L1_scale, -Spscl will make symmetric range around mode (i.e., LMS; least median of squares) and ±scl * LMS_scale, while -Sqlow/high sets the range from low quartile to high quartile (in percentages). We use the last data column for this calculation; use i if you need to adjust the column orders.

-T[min/max/inc[+b|i|l|n]|file|list]

Defines the range of the new CPT by giving the lowest and highest z-value (and optionally an interval). If -T is not given, the existing range in the master CPT will be used intact. The values produces defines the color slice boundaries. If +n is used it refers to the number of such boundaries and not the number of slices. For details on array creation, see Generate 1D Array. Note: To set up categorical CPTs with string keys you can also give a comma-separated list of your keys.

-V[level]

Select verbosity level [w]. (See full description) (See cookbook information).

-W[w]

Do not interpolate the input color table but pick the output colors starting at the beginning of the color table, until colors for all intervals are assigned. This is particularly useful in combination with a categorical color table, like “categorical”. Alternatively, use -Ww to produce a wrapped (cyclic) color table that endlessly repeats its range.

-Z

Force a continuous CPT when building from a list of colors and a list of z-values [discrete].

-birecord[+b|l] (more …)

Select native binary format for primary table input. [Default is the required number of columns given the chosen settings].

-dinodata[+ccol] (more …)

Replace input columns that equal nodata with NaN.

-h[i|o][n][+c][+d][+msegheader][+rremark][+ttitle] (more …)

Skip or produce header record(s).

-icols[+l][+ddivisor][+sscale|d|k][+ooffset][,][,t[word]] (more …)

Select input columns and transformations (0 is first column, t is trailing text, append word to read one word only).

-^ or just -

Print a short message about the syntax of the command, then exit (Note: on Windows just use -).

-+ or just +

Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

Print a complete usage (help) message, including the explanation of all options, then exit.

--PAR=value

Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

Notes on Transparency

The PostScript language originally had no accommodation for transparency. However, Adobe added an extension that allows developers to encode some forms of transparency using the PostScript language model but it is only realized when converting the PostScript to PDF (and via PDF to any raster image format). GMT uses this model but there are some limitations: Transparency can only be controlled on a per-object or per-layer basis. This means that a color specifications (such as those in CPTs of given via command-line options) only apply to vector graphic items (i.e., text, lines, polygon fills) or to an entire layer (which could include items such as PostScript images). This limitation rules out any mechanism of controlling transparency in such images on a pixel level.

Generate 1D Array

We will demonstrate the use of options for creating 1-D arrays via gmtmath. Make an evenly spaced coordinate array from min to max in steps of inc, e.g.,:

gmt math -o0 -T3.1/4.2/0.1 T =
3.1
3.2
3.3
3.4
3.5
3.6
3.7

Append +b if we should take log2 of min and max, get their nearest integers, build an equidistant log2-array using inc integer increments in log2, then undo the log2 conversion. E.g., -T3/20/1+b will produce this sequence:

gmt math -o0 -T3/20/1+b T =
4
8
16

Append +l if we should take log10 of min and max and build an array where inc can be 1 (every magnitude), 2, (1, 2, 5 times magnitude) or 3 (1-9 times magnitude). E.g., -T7/135/2+l will produce this sequence:

gmt math -o0 -T7/135/2+l T =
10
20
50
100

For output values less frequently than every magnitude, use a negative integer inc:

gmt math -o0 -T1e-4/1e4/-2+l T =
0.0001
0.01
1
100
10000

Append +i if inc is a fractional number and it is cleaner to give its reciprocal value instead. To set up times for a 24-frames per second animation lasting 1 minute, run:

gmt math -o0 -T0/60/24+i T =
0
0.0416666666667
0.0833333333333
0.125
0.166666666667
...

Append +n if inc is meant to indicate the number of equidistant coordinates instead. To have exactly 5 equidistant values from 3.44 and 7.82, run:

gmt math -o0 -T3.44/7.82/5+n T =
3.44
4.535
5.63
6.725
7.82

Alternatively, let inc be a file with output coordinates in the first column, or provide a comma-separated list of specific coordinates, such as the first 6 Fibonacci numbers:

gmt math -o0 -T0,1,1,2,3,5 T =
0
1
1
2
3
5

Note: Should you need to ensure that the coordinates are unique and sorted (in case the file or list are not sorted or have duplicates) then supply the +u modifier.

If you only want a single value then you must append a comma to distinguish the list from the setting of an increment.

If the module allows you to set up an absolute time series, append a valid time unit from the list year, month, day, hour, minute, and second to the given increment; add +t to ensure time column (or use -f). Note: The internal time unit is still controlled independently by TIME_UNIT. The first 7 days of March 2020:

gmt math -o0 -T2020-03-01T/2020-03-07T/1d T =
2020-03-01T00:00:00
2020-03-02T00:00:00
2020-03-03T00:00:00
2020-03-04T00:00:00
2020-03-05T00:00:00
2020-03-06T00:00:00
2020-03-07T00:00:00

A few modules allow for +a which will paste the coordinate array to the output table.

Likewise, if the module allows you to set up a spatial distance series (with distances computed from the first two data columns), specify a new increment as inc with a geospatial distance unit from the list degree (arc), minute (arc), second (arc), meter, foot, kilometer, Miles (statute), nautical miles, or survey foot; see -j for calculation mode. To interpolate Cartesian distances instead, you must use the special unit c.

Finally, if you are only providing an increment and will obtain min and max from the data, then it is possible (max - min)/inc is not an integer, as required. If so, then inc will be adjusted to fit the range. Alternatively, append +e to keep inc exact and adjust max instead (keeping min fixed).

Color Hinges

Some of the GMT master dynamic CPTs are actually two separate CPTs meeting at a hinge. Usually, colors may change dramatically across the hinge, which is used to separate two different domains (e.g., land and ocean across the shoreline, for instance). CPTs with a hinge will have their two parts stretched to the required range separately, i.e., the bottom part up to the hinge will be stretched independently of the part from the hinge to the top, according to the prescribed new range. Hinges are either hard or soft. Soft hinges must be activated by appending +h[hinge] to the CPT name. If the selected range does not include an activated soft or hard hinge then we only resample colors from the half of the CPT that pertains to the range. See Of Colors and Color Legends for more information.

Discrete versus Continuous CPT

All CPTs can be stretched, but only continuous CPTs can be sampled at new nodes (i.e., by given an increment in -T). We impose this limitation to avoid aliasing the original CPT.

Examples

Note: Below are some examples of valid syntax for this module. The examples that use remote files (file names starting with @) can be cut and pasted into your terminal for testing. Other commands requiring input files are just dummy examples of the types of uses that are common but cannot be run verbatim as written.

To make a CPT with z-values from -200 to 200, with discrete color changes every 25, and using a polar blue-white-red colortable:

gmt makecpt -Cpolar -T-200/200/25 > colors.cpt

To make an equidistant CPT from z = -2 to 6 using the continuous default turbo rainbow of colors:

gmt makecpt -T-2/6 > colors.cpt

To use the GEBCO look-alike CPT with its default range for bathymetry, run

gmt makecpt -Cgebco > my_gebco.cpt

or simply use -Cgebco directly in the application that needs the color table. To create a 24-level color table suitable for plotting the depths in the remote ata table v3206_06.txt (with lon, lat, depths), run

gmt makecpt -Cgebco @v3206_06.txt -E24 > my_depths.cpt

To use the gebco color table but reverse the z-values so it can be used for positive depth values, try

gmt makecpt -Cgebco -Iz > my_positive_gebco.cpt

To make a custom discrete color table for depth of seismicity, using red color for hypocenters between 0 and 100 km, green for 100-300 km, and blue for deep (300-1000 km) earthquakes, use

gmt makecpt -Cred,green,blue -T0,80,300,1000 -N > seis.cpt

To make a continuous CPT from white to blue as z goes from 3 to 10, try

gmt makecpt -Cwhite,blue -T3/10 > cold.cpt

To make a wrapped (cyclic) CPT from the jet table over the interval 0 to 500, i.e., the color will be wrapped every 500 z-units so that we always get a color regardless of the z value, try

gmt makecpt -Cjet -T0/500 -Ww > wrapped.cpt

To build a categorical table with 3 categories and add specific category names to them, try:

gmt makecpt -Ccubhelix -T0/3/1 -F+cClouds,Trees,Water > cat.cpt

To instead add unique category labels A, B, C, … to a 10-item categorical CPT, try:

gmt makecpt -Cjet -T0/10/1 -F+cA

To make a categorical CPT with string keys instead of numerical lookup values, try:

gmt makecpt -Ccategorical -Twood,water,gold

Note on CPTs in Modern Mode

In modern mode, CPTs are rarely needed to be named explicitly. Instead, when a module that may create a CPT, such as grd2cpt and makecpt (or even grdimage when no color table is available), the behavior under modern mode is to write that CPT to a hidden file in the session directory. When a module requires a CPT (e.g., grdimage not given -C or plot given -C with no name) then we read this hidden CPT (if it exists). This file is called the current CPT. In fact, there are several levels of current CPTs that may all be different, and some may not be present. If you create a CPT within an inset operation then that CPT is only accessible during the inset plotting; it thus only has the inset as its scope. If you create a CPT while positioned into a specific subplot, then that CPT is likewise only accessible to that subplot. If, on the other hand, you make a CPT after subplot begin but before any plotting then that CPT is available to all the subplots (but can be locally overridden by a subplot-specific CPT mention above). Finally, each call to figure means you may have a figure-specific CPT, should you create them. If none exists then the session CPT is used. The rule gmt follows is to always get the CPT with the most restricted scope that is visible from where you are in the plotting hierarchy. If not found we go up the hierarchy to CPTs with broader scope, and if none is ultimately found (and the module, unlike grdimage, cannot create a CPT by itself), then you have likely made a scripting error. There are cases in modern mode when you must explicitly create a named CPT using the -H option. One such case is when making movies with movie since you will want to create the CPT once and have movie access it again and again. Since each movie frame is a separate session there is no cross-session sharing of current CPTs.

See Also

gmt, grd2cpt

References

Crameri, F., (2018). Scientific colour-maps. Zenodo. http://doi.org/10.5281/zenodo.1243862

Crameri, F. (2018), Geodynamic diagnostics, scientific visualisation and StagLab 3.0, Geosci. Model Dev., 11, 2541-2562, doi:10.5194/gmd-11-2541-2018.