Reproducing line colors with a custom CPT tutorial


I’ve tried to reproduce this tutorial and noticed that the output of this looks like this:

rather than

as indicated on the tutorial’s website. (Note the labeling of the colorbar for both plots)

How can I get the colorbar labeling of the second figure (integers rather than ranges)?

The source code was just copied from the website, and looks like this:

import numpy as np
import pygmt

# Create a list of values between 20 and 30 with 0.2 intervals
x = np.arange(start=20, stop=30, step=0.2)

fig = pygmt.Figure()
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])

# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors),
# use color_model="+c0-9" to write the color palette in categorical format and
# add labels (0) to (9) for the colorbar legend
pygmt.makecpt(cmap="batlow", series=[0, 9, 1], color_model="+c0-9")

# Plot 10 lines and set a different z-value for each line
for zvalue in range(0, 10):
y = zvalue * np.sin(x)
fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen="thick,+z,-")

# Color bar to show the custom CPT and the associated z-values


Hi @TheGermanSquirrel,
I am also facing the similar issues. In Pygmt there is no flexibility of adding string variables in the colorbar title or any titles/legends. This is the major issue.
One way to solve this issue is by importing the plot without any colorbar labels to the Microsoft powerpoint and manually labeling this.

I think the Pygmt developers should add as a new feature in the upcoming updates.

@TheGermanSquirrel Are you using the latest GMT and PyGMT versions? I think there may be problems with old GMT versions and the PyGMT gallery examples are generated using the latest GMT version (i.e., GMT 6.4.0 now).