The annotation of Colorbar in PyGMT

Hey everyone,
Can PyGMT draw the colorbar like the picture below, and the annotation contains the units.

Hello wensentry,

yes, it is possible to add the unit to the single values of the colorbar annotation:

import pygmt

size = 5

fig = pygmt.Figure()

    region=[-size, size, -size, size],
    projection="X" + str(size*2) + "c",

# Append +u with the desired unit to the argument for the x axis
# and pass it to the frame parameter
fig.colorbar(cmap="batlow", frame="x+uK")

Output figure:

Hello @yvonnefroehlich Thank you so much for your help. It works.

import pygmt

fig = pygmt.Figure()

lowest = -15
highest = 15
interval = (highest - lowest) / 64

pygmt.config(FONT_TITLE="18p,5", FONT_LABEL="16p,4", FONT_ANNOT_PRIMARY="10p,4", MAP_TITLE_OFFSET="-12p", MAP_FRAME_TYPE="plain")

pygmt.makecpt(cmap="Purple_Orange.cpt", series=[lowest, highest, interval])
fig.grdimage(grid=r'276_chazhi_TWSDSTF.tif', frame=["lbtr"], cmap=True)
fig.colorbar(cmap=True, position="JMR+w5c/0.5c", frame=["x+uK"])

Output figure :

I have one more question. How to set the colorbar annotation to show only the minimum,0 and maximum values with unit? The final result I would like to get is shown below.

Data and CPT file :

In your case, you can achieve this by specify the step of the annotation:

fig.colorbar(cmap=True, position="JMR+w5c/0.5c", frame=["xa15+uK"])

@yvonnefroehlich Thank you for your reply! It has resolved the issue I was having.