GenericMappingTools / gmt

The Generic Mapping Tools
https://www.generic-mapping-tools.org
Other
847 stars 355 forks source link

Background and foreground colors for categorical CPTs #3766

Closed seisman closed 3 years ago

seisman commented 4 years ago

Description of the problem

As per the documentation:

For categorical data, background color or foreground color do not apply.

The actual behavior is inconsistent with the documentation.

Full script that generated the error

gmt begin map png

cat > types.cpt << EOF
0   yellow   ;desert
1   blue     ;forest
2   red      ;iceland
B   white
F   black
N   gray
EOF

gmt plot -R0/12/0/6 -Jx1c -Baf -BWSen -Sc0.8c -W1p -Ctypes.cpt << EOF
1  3  -1
2  3  0
3  3  1
4  3  1.5
5  3  2
6  3  3
7  3  3.1
8 3  NaN
EOF

gmt colorbar -Ctypes.cpt -DJBC+e+n
gmt end show

Actual outcome

image

Expected outcome

The figure doesn't match the documentation:

  1. It seems background and foreground colors (white and black) still works for categorical CPTs with numeric keys. If yes, we need to document it better, otherwise it's a bug.
  2. If YES for point 1, then here is another bug. The color of the circle with z=3 should have a foreground color (black), but now it's red. If I change z=3 to z=3.1, it's black.
  3. z=1.5 is in blue, but for categorical data, z=1.5 is an undefined value.

System information

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

PaulWessel commented 3 years ago

I do not think we have checks that might apply to categorical data. We should check that the input z value exactly matches the entries in the CPT and not the z = 1.5 which should give an error. People who want z from 1-2 to give a constant color should use an discrete CPT, not a categorical one. So we should start with implementing that test. Likewise I think back and foreground does not make too much sense either but I suppose for numerical categories we could allow that. For key-based categorically we clearly should not allow it. I will see what checks I can add.

PaulWessel commented 3 years ago

Shall we distinguish between numerical categorical CPTs and key-based (e.g. text) categorical CPTs? I see the CPT has an unsigned int categorical that is used as a bit flag and bits 1 and 2 are set but I see no use of the bits, just that it is nonzero. I am pretty sure that if you have categories, then any value not among the listed categories should return NaN and there cannot be a fore and background color. It should not matter that the keys happen to be numbers or strings.

seisman commented 3 years ago

I am pretty sure that if you have categories, then any value not among the listed categories should return NaN and there cannot be a fore and background color. It should not matter that the keys happen to be numbers or strings.

Yes, it makes more sense to me.

seisman commented 3 years ago

Closed #4407.