Skip to content

Commit 1e14c33

Browse files
committed
Alias box (F) for colorbar
Including tests for controlling how the border around the color scalebar is styled.
1 parent 9947a96 commit 1e14c33

9 files changed

+92
-1
lines changed

pygmt/base_plotting.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def coast(self, **kwargs):
126126
lib.call_module("coast", build_arg_string(kwargs))
127127

128128
@fmt_docstring
129-
@use_alias(R="region", J="projection", B="frame", C="cmap", D="position")
129+
@use_alias(R="region", J="projection", B="frame", C="cmap", D="position", F="box")
130130
@kwargs_to_strings()
131131
def colorbar(self, **kwargs):
132132
"""
@@ -162,6 +162,26 @@ def colorbar(self, **kwargs):
162162
corner (BL), but this can be changed by appending +j followed by a 2-char
163163
justification code justify.
164164
165+
box (F) : bool or str
166+
``[+cclearances][+gfill][+i[[gap/]pen]][+p[pen]][+r[radius]][+s[[dx/dy/]
167+
[shade]]]``.
168+
If set to True, draws a rectangular border around the color scale.
169+
Alternatively, specify a different pen with +ppen.
170+
Add +gfill to fill the scale panel [no fill].
171+
Append +cclearance where clearance is either gap, xgap/ygap, or
172+
lgap/rgap/bgap/tgap where these items are uniform, separate in x- and
173+
y-direction, or individual side spacings between scale and border.
174+
Append +i to draw a secondary, inner border as well. We use a uniform gap
175+
between borders of 2p and the MAP_DEFAULTS_PEN unless other values are
176+
specified.
177+
Append +r to draw rounded rectangular borders instead, with a 6p corner
178+
radius. You can override this radius by appending another value.
179+
Finally, append +s to draw an offset background shaded region. Here, dx/dy
180+
indicates the shift relative to the foreground frame [4p/-4p] and shade sets
181+
the fill style to use for shading [gray50].
182+
183+
184+
165185
{aliases}
166186
"""
167187
kwargs = self._preprocess(**kwargs)
1.48 KB
Loading
Loading
Loading
Loading
Loading
Loading
Loading

pygmt/tests/test_colorbar.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,74 @@ def test_colorbar_positioned_using_normalized_coords():
5757
fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True)
5858
fig.colorbar(cmap="rainbow", position="n0.75/0.25+w2c")
5959
return fig
60+
61+
62+
@pytest.mark.mpl_image_compare
63+
def test_colorbar_box():
64+
"""
65+
Create colorbar with box around it.
66+
"""
67+
fig = Figure()
68+
fig.colorbar(cmap="rainbow", box=True, position="x0c/0c+w1c/0.5c")
69+
return fig
70+
71+
72+
@pytest.mark.mpl_image_compare
73+
def test_colorbar_box_with_pen():
74+
"""
75+
Create colorbar with box that has a different colored pen.
76+
"""
77+
fig = Figure()
78+
fig.colorbar(cmap="rainbow", box="+porange", position="x0c/0c+w1c/0.5c")
79+
return fig
80+
81+
82+
@pytest.mark.mpl_image_compare
83+
def test_colorbar_box_with_fill():
84+
"""
85+
Create colorbar with box that has a different colored fill.
86+
"""
87+
fig = Figure()
88+
fig.colorbar(cmap="rainbow", box="+gorange", position="x0c/0c+w1c/0.5c")
89+
return fig
90+
91+
92+
@pytest.mark.mpl_image_compare
93+
def test_colorbar_box_with_clearance():
94+
"""
95+
Create colorbar with box that has an x-clearance of 0.8cm and y-clearance of 0.4cm.
96+
"""
97+
fig = Figure()
98+
fig.colorbar(cmap="rainbow", box="+c0.8c/0.4c+porange", position="x0c/0c+w1c/0.5c")
99+
return fig
100+
101+
102+
@pytest.mark.mpl_image_compare
103+
def test_colorbar_box_with_secondary_border():
104+
"""
105+
Create colorbar with box that has a secondary, inner border in addition to the main
106+
primary, outer border.
107+
"""
108+
fig = Figure()
109+
fig.colorbar(cmap="rainbow", box="+porange+imagenta", position="x0c/0c+w1c/0.5c")
110+
return fig
111+
112+
113+
@pytest.mark.mpl_image_compare
114+
def test_colorbar_box_with_rounded_corners():
115+
"""
116+
Create colorbar with box that has rounded corners.
117+
"""
118+
fig = Figure()
119+
fig.colorbar(cmap="rainbow", box="+porange+r", position="x0c/0c+w1c/0.5c")
120+
return fig
121+
122+
123+
@pytest.mark.mpl_image_compare
124+
def test_colorbar_box_with_offset_background():
125+
"""
126+
Create colorbar with box and an offset background shaded region.
127+
"""
128+
fig = Figure()
129+
fig.colorbar(cmap="rainbow", box="+s5p/-5p", position="x0c/0c+w1c/0.5c")
130+
return fig

0 commit comments

Comments
 (0)