Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem labelling equal size colorbar #896

Closed
amarux opened this issue May 19, 2022 · 3 comments
Closed

Problem labelling equal size colorbar #896

amarux opened this issue May 19, 2022 · 3 comments

Comments

@amarux
Copy link

amarux commented May 19, 2022

Hi!

I am having problems trying to label a discrete equal size color bar.
For example, I am using:

cpt_test  = makecpt(cmap=(:forestgreen,:darkseagreen3,:darkorange1,:red3,:steelblue4), range=(1,6,1),  no_bg=true)
cpt_test.label = ["Good", "Probgood", "Probbad", "bad", "changed"]
colorbar(pos=(paper=true, anchor="2.5i/1i", justify=:CM, size=(1.7,0.22)), axes=:none,  equal=(gap=0.1), cmap=cpt_test, show=1)

With this code I got a color bar labelled with the "lower boundary z-value for the annotation", as indicated in the documentation
However, I am wondering if in GMT.jl I could get something like the image below

image

Thank you!

@joa-quim
Copy link
Member

Hi @amarux,

Well I think you found a bug in GMT. More specifically in the internal machinery that communicates with external interfaces like is the case with Julia. The problem seems to be that the labels are ignored.
But you can make it work with a trick. Save the colormap into a disk file, open it in an editor and add the labels at the end of each line.

gmtwrite("test.cpt", test_cpt)

then, after the edition the contents look like this

1	forestgreen	2	forestgreen	;Good
2	darkseagreen3	3	darkseagreen3	;Probgood
3	darkorange1	4	darkorange1	;Probbad
4	red3	5	red3	;bad
5	steelblue4	6	steelblue4	;changed
B	black
F	white
N	128

next this works (you we mixing inches and cm. Life is simpler in cm).

colorbar(pos=(paper=true, anchor="2.5i/1i", justify=:CM, size=("1.7i","0.22i")), axes=:none,  equal=(gap=0.1), cmap="test.cpt", show=1)

GMTjl_tmp

@joa-quim
Copy link
Member

Hmm, it actually works if we do as said in the manual (the makecpt GMT man) and put the labels in the T or range option.

test_cpt  = makecpt(cmap=(:forestgreen,:darkseagreen3,:darkorange1,:red3,:steelblue4), no_bg=true, range="Good,Probgood,Probbad,bad,changed");

@amarux
Copy link
Author

amarux commented May 25, 2022

Nice! Thank you again!

@amarux amarux closed this as completed May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants