Skip to content

Commit 01b563c

Browse files
committed
Use Box in examples and tests
1 parent 9f08d1b commit 01b563c

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

examples/gallery/images/cross_section.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# %%
1616
import pygmt
17+
from pygmt.params import Box
1718

1819
# Define region of study area
1920
# lon_min, lon_max, lat_min, lat_max in degrees East and North
@@ -44,9 +45,9 @@
4445
# corner with an offset ("+o") of 0.7 centimeters and 0.3 centimeters in x- or y-
4546
# directions, respectively; move the x-label above the horizontal colorbar ("+ml")
4647
position="jBR+o0.7c/0.8c+h+w5c/0.3c+ml",
47-
# Add a box around the colobar with a fill ("+g") in "white" color and a
48-
# transparency ("@") of 30 % and with a 0.8-points thick, black, outline ("+p")
49-
box="+gwhite@30+p0.8p,black",
48+
# Add a box around the colobar, filled in "white" and a 30% transparency, with a
49+
# 0.8-points thick, black, outline.
50+
box=Box(pen="0.8p,black", fill="white@30"),
5051
# Add x- and y-labels ("+l")
5152
frame=["x+lElevation", "y+lm"],
5253
)

examples/gallery/lines/hlines_vlines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# In Cartesian coordinate systems lines are plotted as straight lines.
1313

1414
import pygmt
15+
from pygmt.params import Box
1516

1617
fig = pygmt.Figure()
1718

@@ -31,7 +32,7 @@
3132
fig.hlines(
3233
y=[2, 3], xmin=[0, 1], xmax=[7, 7.5], pen="1.5p,dodgerblue3", label="Lines 7 & 8"
3334
)
34-
fig.legend(position="JBR+jBR+o0.2c", box="+gwhite+p1p")
35+
fig.legend(position="JBR+jBR+o0.2c", box=Box(pen="1p", fill="white"))
3536

3637
fig.shift_origin(xshift="w+2c")
3738

examples/tutorials/advanced/insets.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# %%
1212
import pygmt
13+
from pygmt.params import Box
1314

1415
# %%
1516
# Prior to creating an inset figure, a larger figure must first be plotted. In
@@ -48,7 +49,7 @@
4849
water="lightblue",
4950
frame="a",
5051
)
51-
with fig.inset(position="jBL+w3c", box="+pblack+glightred"):
52+
with fig.inset(position="jBL+w3c", box=Box(pen="black", fill="lightred")):
5253
# pass is used to exit the with statement as no plotting methods are
5354
# called
5455
pass
@@ -72,7 +73,7 @@
7273
water="lightblue",
7374
frame="a",
7475
)
75-
with fig.inset(position="jBL+w3c+o0.5c/0.2c", box="+pblack+glightred"):
76+
with fig.inset(position="jBL+w3c+o0.5c/0.2c", box=Box(pen="black", fill="lightred")):
7677
pass
7778
fig.show()
7879

@@ -97,7 +98,7 @@
9798
# parameters.
9899
with fig.inset(
99100
position="jBL+o0.5c/0.2c",
100-
box="+pblack",
101+
box=Box(pen="black"),
101102
region=[-80, -65, 35, 50],
102103
projection="M3c",
103104
):

pygmt/src/inset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ def inset(self, **kwargs):
113113
Examples
114114
--------
115115
>>> import pygmt
116+
>>> from pygmt.params import Box
116117
>>>
117118
>>> # Create the larger figure
118119
>>> fig = pygmt.Figure()
119120
>>> fig.coast(region="MG+r2", water="lightblue", shorelines="thin")
120121
>>> # Use a "with" statement to initialize the inset context manager
121122
>>> # Setting the position to top left and a width of 3.5 centimeters
122-
>>> with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box="+pgreen"):
123+
>>> with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box=Box(pen="green")):
123124
... # Map elements under the "with" statement are plotted in the inset
124125
... fig.coast(
125126
... region="g",

pygmt/tests/test_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pygmt import Figure
7+
from pygmt.params import Box
78

89

910
@pytest.mark.mpl_image_compare
@@ -12,5 +13,5 @@ def test_image():
1213
Place images on map.
1314
"""
1415
fig = Figure()
15-
fig.image(imagefile="@circuit.png", position="x0/0+w2c", box="+pthin,blue")
16+
fig.image(imagefile="@circuit.png", position="x0/0+w2c", box=Box(pen="thin,blue"))
1617
return fig

pygmt/tests/test_inset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pygmt import Figure
7+
from pygmt.params import Box
78

89

910
@pytest.mark.benchmark
@@ -14,7 +15,7 @@ def test_inset_aliases():
1415
"""
1516
fig = Figure()
1617
fig.basemap(region="MG+r2", frame="afg")
17-
with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box="+pgreen"):
18+
with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box=Box(pen="green")):
1819
fig.basemap(region="g", projection="G47/-20/4c", frame="afg")
1920
return fig
2021

@@ -27,7 +28,7 @@ def test_inset_context_manager():
2728
"""
2829
fig = Figure()
2930
fig.basemap(region=[-74, -69.5, 41, 43], projection="M9c", frame=True)
30-
with fig.inset(position="jBL+w3c+o0.2c", margin=0, box="+pblack"):
31+
with fig.inset(position="jBL+w3c+o0.2c", margin=0, box=Box(pen="black")):
3132
fig.basemap(region=[-80, -65, 35, 50], projection="M3c", frame="afg")
3233
fig.basemap(rose="jTR+w3c") # Pass rose argument with basemap after the inset
3334
return fig

0 commit comments

Comments
 (0)