Skip to content

Commit be5141c

Browse files
committed
Alias cyclic (Ww) and ensure this cannot be used with categorical (W)
1 parent 65d057c commit be5141c

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

pygmt/mathops.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
T="series",
2222
V="verbose",
2323
W="categorical",
24+
Ww="cyclic",
2425
Z="continuous",
2526
)
2627
@kwargs_to_strings(T="sequence", G="sequence")
@@ -135,16 +136,19 @@ def makecpt(**kwargs):
135136
Force a continuous CPT when building from a list of colors and a list
136137
of z-values [Default is None, i.e. discrete values].
137138
{V}
138-
categorical : bool or str
139+
categorical : bool
139140
Do not interpolate the input color table but pick the output colors
140141
starting at the beginning of the color table, until colors for all
141142
intervals are assigned. This is particularly useful in combination with
142-
a categorical color table, like "categorical". Alternatively, use
143-
``categorical='w'`` to produce a wrapped (cyclic) color table that
144-
endlessly repeats its range.
145-
143+
a categorical color table, like ``cmap='categorical'``.
144+
cyclic : bool
145+
Produce a wrapped (cyclic) color table that endlessly repeats its
146+
range. Note that ``cyclic=True`` cannot be set together with
147+
``categorical=True``.
146148
"""
147149
with Session() as lib:
150+
if "W" in kwargs and "Ww" in kwargs:
151+
raise GMTInvalidInput("Set only categorical or cyclic to True, not both.")
148152
if "H" not in kwargs.keys(): # if no output is set
149153
arg_str = build_arg_string(kwargs)
150154
elif "H" in kwargs.keys(): # if output is set

pygmt/tests/test_makecpt.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,41 @@ def test_makecpt_continuous(grid):
182182
makecpt(cmap="blue,white", continuous=True, series="-4500,4500")
183183
fig.grdimage(grid, projection="W0/6i")
184184
return fig
185+
186+
187+
@check_figures_equal()
188+
def test_makecpt_categorical(region):
189+
"""
190+
Use static color palette table that is categorical.
191+
"""
192+
fig_ref = Figure()
193+
makecpt(C="categorical", W="")
194+
fig_ref.colorbar(cmap=True, region=region, frame=True, position="JBC")
195+
196+
fig_test = Figure()
197+
makecpt(cmap="categorical", categorical=True)
198+
fig_test.colorbar(cmap=True, region=region, frame=True, position="JBC")
199+
return fig_ref, fig_test
200+
201+
202+
@check_figures_equal()
203+
def test_makecpt_cyclic(region):
204+
"""
205+
Use static color palette table that is cyclic.
206+
"""
207+
fig_ref = Figure()
208+
makecpt(C="cork", W="w")
209+
fig_ref.colorbar(cmap=True, region=region, frame=True, position="JBC")
210+
211+
fig_test = Figure()
212+
makecpt(cmap="cork", cyclic=True)
213+
fig_test.colorbar(cmap=True, region=region, frame=True, position="JBC")
214+
return fig_ref, fig_test
215+
216+
217+
def test_makecpt_categorical_and_cyclic():
218+
"""
219+
Use incorrect setting by setting both categorical and cyclic to True.
220+
"""
221+
with pytest.raises(GMTInvalidInput):
222+
makecpt(cmap="batlow", categorical=True, cyclic=True)

0 commit comments

Comments
 (0)