pyGMT makecpt error: CPT <stdin> has no z-slices!

Hi,

I’d like to invert a (built-in) colour map. I adapted a code from another thread (pyGMT makecpt - background and foreground) to arrive at:
pygmt.makecpt(cmap = "devon", reverse = True, series = [0, 7000, 10], output="devon_r.cpt", continuous = True, M = True)
I have also tried M=" " and running without series=[]

However, when I use this colourmap to plot something, it does plot the colourmap correctly inverted, but no colourbar below the map, and pyGMT returns the error colorbar [ERROR]: CPT <stdin> has no z-slices!.

I have tried the pyGMT manual and tutorials but I have not been able to identify the problem in my code.

Many thanks!!
Thomas

I’m not sure how it works with python, but do you ask for the colorbar to be plotted while specifying the cpt’s name?

Hello! I have the same question when I plot the puctures using the GMT ,have you solved the problem ?

Please open a separate post and show your script so that we can see what’s happening.

Hello,when I use the seis and polar scale, I get an error like “makecpt: Error: CPT polar.cpt has no z-slices!” May I ask why this is and how to solve it

It just likes below
[zhongen@localhost gmtplot]$ gmt makecpt -Cpolar -T3/4/0.3 -I -Z > seis.cpt
makecpt: Error: CPT polar.cpt has no z-slices!
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)
[Session gmt (0)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)

The command works well for me.

So could it be the version ?

So could it be the version?

No.

But a broken installation maybe.

OK,thank you for your reply. I’ll try to install it again

Just a short comment on this conversation:

In the first post (pyGMT makecpt error: CPT <stdin> has no z-slices!), the error
colorbar [ERROR]: CPT <stdin> has no z-slices!
is reported.

Now we have (pyGMT makecpt error: CPT <stdin> has no z-slices! - #6 by yangxuan) the error
makecpt: Error: CPT polar.cpt has no z-slices!

Also we are jumping from PyGMT to GMT.


The first error occurs, if users save their colormap first to a file via the output parameter of pygmt.makecpt and later use cmap=True within Figure.colorbar. This does not work. If you save your colormap to a file you have to pass the used filename to cmap of Figure.colorbar:

import pygmt

size = 5

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

pygmt.makecpt(cmap="polar", series=[0, 10, 1], output="polar_test.cpt")
# colormap is saved to a file via the "output" parameter

# fig.colorbar(cmap=True)  # fails with
# colorbar [ERROR]: CPT <stdin> has no z-slices!
# [Session pygmt-session (33)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)
# [Session pygmt-session (33)]: Error returned from GMT API: GMT_CPT_READ_ERROR (8)

fig.colorbar(cmap="polar_test.cpt") # works
# Users need to pass the filename of the colormap if the created colormap was saved to a file

fig.show()

For the second issue in GMT, I feel we need your GMT script and it makes sense to start a separate topic as already mentioned by @seisman :slightly_smiling_face: .