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

Add the shading parameter to colorbar() in base_plotting.py #752

Merged
merged 17 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,15 @@ def coast(self, **kwargs):
D="position",
F="box",
G="truncate",
I="shading",
W="scale",
V="verbose",
X="xshift",
Y="yshift",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", G="sequence", p="sequence")
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
def colorbar(self, **kwargs):
"""
Plot a gray or color scale-bar on maps.
Expand Down Expand Up @@ -223,6 +224,12 @@ def colorbar(self, **kwargs):
scale : float
Multiply all z-values in the CPT by the provided scale. By default
the CPT is used as is.
shading : str or list or bool
Add illumination effects. Optionally, set the range of intensities
from -max_intens to +max_intens. If not specified, 1 is used.
Alternatively, set ``shading=[low, high]`` to specify an
asymmetric intensity range from *low* to *high*.
The default is no illumination.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{V}
{XY}
{p}
Expand Down
60 changes: 60 additions & 0 deletions pygmt/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,63 @@ def test_colorbar_scaled_z_values():
fig = Figure()
fig.colorbar(cmap="rainbow", scale=0.1, position="x0c/0c+w2c/0.5c")
return fig


@check_figures_equal()
def test_colorbar_shading_boolean():
"""
Create colorbar and set shading with a Boolean value
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I=True)
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=True)
return fig_ref, fig_test


@check_figures_equal()
def test_colorbar_shading_float():
"""
Create colorbar and set shading with a single float variable
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="0.5")
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=0.5)
return fig_ref, fig_test


@check_figures_equal()
def test_colorbar_shading_string():
"""
Create colorbar and set shading by passing the high/low values as a string
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="-0.7/0.2")

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading="-0.7/0.2")
return fig_ref, fig_test


@check_figures_equal()
def test_colorbar_shading_list():
"""
Create colorbar and set shading by passing the high/low values as a list
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
fig_ref.basemap(R="0/10/0/10", J="X15c", B="a")
fig_ref.colorbar(C="geo", I="-0.7/0.2")

fig_test.basemap(region=[0, 10, 0, 10], projection="X15c", frame="a")
fig_test.colorbar(cmap="geo", shading=[-0.7, 0.2])
return fig_ref, fig_test