Skip to content

Commit 27a58e8

Browse files
Add the shading parameter to colorbar() in base_plotting.py (#752)
* Add the shading parameter to colorbar() in base_plotting.py * Update pygmt/tests/test_colorbar.py Co-authored-by: Dongdong Tian <[email protected]>
1 parent cad05b0 commit 27a58e8

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

pygmt/base_plotting.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ def coast(self, **kwargs):
153153
D="position",
154154
F="box",
155155
G="truncate",
156+
I="shading",
156157
W="scale",
157158
V="verbose",
158159
X="xshift",
159160
Y="yshift",
160161
p="perspective",
161162
t="transparency",
162163
)
163-
@kwargs_to_strings(R="sequence", G="sequence", p="sequence")
164+
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
164165
def colorbar(self, **kwargs):
165166
"""
166167
Plot a gray or color scale-bar on maps.
@@ -223,6 +224,11 @@ def colorbar(self, **kwargs):
223224
scale : float
224225
Multiply all z-values in the CPT by the provided scale. By default
225226
the CPT is used as is.
227+
shading : str or list or bool
228+
Add illumination effects. Passing a single numerical value sets the range
229+
of intensities from -value to +value. If not specified, 1 is used.
230+
Alternatively, set ``shading=[low, high]`` to specify an asymmetric
231+
intensity range from *low* to *high*. The default is no illumination.
226232
{V}
227233
{XY}
228234
{p}

pygmt/tests/test_colorbar.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,63 @@ def test_colorbar_scaled_z_values():
153153
fig = Figure()
154154
fig.colorbar(cmap="rainbow", scale=0.1, position="x0c/0c+w2c/0.5c")
155155
return fig
156+
157+
158+
@check_figures_equal()
159+
def test_colorbar_shading_boolean():
160+
"""
161+
Create colorbar and set shading with a Boolean value
162+
"""
163+
fig_ref, fig_test = Figure(), Figure()
164+
# Use single-character arguments for the reference image
165+
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
166+
fig_ref.colorbar(C="geo", I="")
167+
168+
fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
169+
fig_test.colorbar(cmap="geo", shading=True)
170+
return fig_ref, fig_test
171+
172+
173+
@check_figures_equal()
174+
def test_colorbar_shading_float():
175+
"""
176+
Create colorbar and set shading with a single float variable
177+
"""
178+
fig_ref, fig_test = Figure(), Figure()
179+
# Use single-character arguments for the reference image
180+
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
181+
fig_ref.colorbar(C="geo", I=0.5)
182+
183+
fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
184+
fig_test.colorbar(cmap="geo", shading=0.5)
185+
return fig_ref, fig_test
186+
187+
188+
@check_figures_equal()
189+
def test_colorbar_shading_string():
190+
"""
191+
Create colorbar and set shading by passing the low/high values as a string
192+
"""
193+
fig_ref, fig_test = Figure(), Figure()
194+
# Use single-character arguments for the reference image
195+
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
196+
fig_ref.colorbar(C="geo", I="-0.7/0.2")
197+
198+
fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
199+
fig_test.colorbar(cmap="geo", shading="-0.7/0.2")
200+
return fig_ref, fig_test
201+
202+
203+
@check_figures_equal()
204+
def test_colorbar_shading_list():
205+
"""
206+
Create colorbar and set shading by passing the high/low values as a list
207+
"""
208+
fig_ref, fig_test = Figure(), Figure()
209+
# Use single-character arguments for the reference image
210+
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
211+
fig_ref.colorbar(C="geo", I="-0.7/0.2")
212+
213+
fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
214+
fig_test.colorbar(cmap="geo", shading=[-0.7, 0.2])
215+
return fig_ref, fig_test

0 commit comments

Comments
 (0)