diff --git a/examples/gallery/images/cross_section.py b/examples/gallery/images/cross_section.py index fc29fe2252c..822b971c92c 100644 --- a/examples/gallery/images/cross_section.py +++ b/examples/gallery/images/cross_section.py @@ -14,7 +14,7 @@ # %% import pygmt -from pygmt.params import Axis, Box, Position +from pygmt.params import Axis, Box, Frame, Position # Define region of study area # lon_min, lon_max, lat_min, lat_max in degrees East and North @@ -120,6 +120,12 @@ # Add map frame # Add annotations ("a") and ticks ("f") as well as labels ("+l") at the west or left # and south or bottom sides ("WSrt") -fig.basemap(frame=["WSrt", "xa2f1+lDistance+u°", "ya4000+lElevation / m"]) +fig.basemap( + frame=Frame( + axes="WSrt", + xaxis=Axis(annot=2, tick=1, label="Distance", unit="°"), + yaxis=Axis(annot=4000, label="Elevation / m"), + ) +) fig.show() diff --git a/examples/gallery/images/grdclip.py b/examples/gallery/images/grdclip.py index 17990e6f641..047599e26ad 100644 --- a/examples/gallery/images/grdclip.py +++ b/examples/gallery/images/grdclip.py @@ -10,7 +10,7 @@ # %% import pygmt -from pygmt.params.position import Position +from pygmt.params import Axis, Frame, Position fig = pygmt.Figure() @@ -24,7 +24,12 @@ fig.basemap( region=region, projection="M12c", - frame=["WSne+toriginal grid", "xa5f1", "ya2f1"], + frame=Frame( + axes="WSne", + title="original grid", + xaxis=Axis(annot=5, tick=1), + yaxis=Axis(annot=2, tick=1), + ), ) fig.grdimage(grid=grid, cmap="SCM/oleron") @@ -39,7 +44,12 @@ fig.basemap( region=region, projection="M12c", - frame=["wSne+tclipped grid", "xa5f1", "ya2f1"], + frame=Frame( + axes="wSne", + title="clipped grid", + xaxis=Axis(annot=5, tick=1), + yaxis=Axis(annot=2, tick=1), + ), ) fig.grdimage(grid=grid) fig.colorbar( diff --git a/examples/gallery/images/grdgradient.py b/examples/gallery/images/grdgradient.py index 86cf9fc8cf8..1206de94b00 100644 --- a/examples/gallery/images/grdgradient.py +++ b/examples/gallery/images/grdgradient.py @@ -13,7 +13,7 @@ # %% import pygmt -from pygmt.params import Position +from pygmt.params import Axis, Frame, Position # Define region of interest around Yosemite valley region = [-119.825, -119.4, 37.6, 37.825] @@ -35,7 +35,12 @@ fig.grdimage( grid=grid, projection="M12c", - frame=["WSrt+tOriginal Data Elevation Model", "xa0.1", "ya0.1"], + frame=Frame( + axes="WSrt", + title="Original Data Elevation Model", + xaxis=Axis(annot=0.1), + yaxis=Axis(annot=0.1), + ), cmap=True, ) fig.colorbar( @@ -57,7 +62,9 @@ fig.grdimage( grid=dgrid, projection="M12c", - frame=["lSEt+tHillshade Map", "xa0.1", "ya0.1"], + frame=Frame( + axes="lSEt", title="Hillshade Map", xaxis=Axis(annot=0.1), yaxis=Axis(annot=0.1) + ), cmap=True, ) diff --git a/examples/gallery/images/grdgradient_shading.py b/examples/gallery/images/grdgradient_shading.py index f040c19b49e..ac4df0aaf72 100644 --- a/examples/gallery/images/grdgradient_shading.py +++ b/examples/gallery/images/grdgradient_shading.py @@ -22,7 +22,7 @@ # %% import pygmt -from pygmt.params import Position +from pygmt.params import Axis, Frame, Position # Load the 3 arc-minutes global relief grid in the target area around Caucasus grid = pygmt.datasets.load_earth_relief(resolution="03m", region=[35, 50, 35, 45]) @@ -58,10 +58,10 @@ grid=grid, shading=shade, projection="M?", - frame=[ - "a4f2", - f"+tazimuth={azi}, normalize={normalize}, amp={amp}", - ], + frame=Frame( + title=f"azimuth={azi}, normalize={normalize}, amp={amp}", + axis=Axis(annot=4, tick=2), + ), cmap=True, panel=True, ) diff --git a/examples/gallery/images/rgb_image.py b/examples/gallery/images/rgb_image.py index af548c7c0b3..07f656cdb84 100644 --- a/examples/gallery/images/rgb_image.py +++ b/examples/gallery/images/rgb_image.py @@ -18,6 +18,7 @@ # %% import pygmt import rioxarray +from pygmt.params import Axis, Frame # %% # Read 3-band data from GeoTIFF into an xarray.DataArray object: @@ -38,6 +39,10 @@ grid=image, # Use a map scale where 1 cm on the map equals 1 km on the ground projection="x1:100000", - frame=[r"WSne+tL@!a¯hain@!a¯, Hawai`i on 9 Aug 2023", "af"], + frame=Frame( + axes="WSne", + title=r"L@!a¯hain@!a¯, Hawai`i on 9 Aug 2023", + axis=Axis(annot=True, tick=True), + ), ) fig.show() diff --git a/examples/gallery/lines/connection_lines.py b/examples/gallery/lines/connection_lines.py index 41c2a761863..d29b5123674 100644 --- a/examples/gallery/lines/connection_lines.py +++ b/examples/gallery/lines/connection_lines.py @@ -11,6 +11,7 @@ # %% import pygmt +from pygmt.params import Axis, Frame # Set up same sample data x = [2.2, 3.3, -3.1, -3.7, -0.1] @@ -21,7 +22,11 @@ # ----------------------------------------------------------------------------- # Left: record order -fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["WSne", "af"]) +fig.basemap( + region=[-5, 5, -5, 5], + projection="X6c", + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), +) # Connect data points based on the record order [Default connection=None] fig.plot(x=x, y=y, pen="1.5p,dodgerblue") @@ -32,7 +37,11 @@ # ----------------------------------------------------------------------------- # Middle: network -fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"]) +fig.basemap( + region=[-5, 5, -5, 5], + projection="X6c", + frame=Frame(axes="wSne", axis=Axis(annot=True, tick=True)), +) # Connect data points as network fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="n") @@ -43,7 +52,11 @@ # ----------------------------------------------------------------------------- # Right: reference point -fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"]) +fig.basemap( + region=[-5, 5, -5, 5], + projection="X6c", + frame=Frame(axes="wSne", axis=Axis(annot=True, tick=True)), +) # Connect data points with the reference point (0,0) fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="p0/0") diff --git a/examples/gallery/lines/envelope.py b/examples/gallery/lines/envelope.py index 903b82657fe..bcf4f8b1227 100644 --- a/examples/gallery/lines/envelope.py +++ b/examples/gallery/lines/envelope.py @@ -11,6 +11,7 @@ # %% import pandas as pd import pygmt +from pygmt.params import Axis, Frame # Define a pandas.DataFrame with columns for x and y as well as the lower and upper # deviations @@ -41,7 +42,12 @@ fig.basemap( region=[0, 10, -1.5, 1.5], projection="X10c", - frame=["WSne+tsymmetric deviations +d", "xa2f1", "ya1f0.1"], + frame=Frame( + axes="WSne", + title="symmetric deviations +d", + xaxis=Axis(annot=2, tick=1), + yaxis=Axis(annot=1, tick=0.1), + ), ) # Plot a symmetrical envelope based on the deviations ("+d") @@ -64,7 +70,12 @@ fig.basemap( region=[0, 10, -1.5, 1.5], projection="X10c", - frame=["WSne+tasymmetric deviations +D", "xa2f1", "yf0.1"], + frame=Frame( + axes="WSne", + title="asymmetric deviations +D", + xaxis=Axis(annot=2, tick=1), + yaxis=Axis(tick=0.1), + ), ) # Plot an asymmetrical envelope based on the deviations ("+D") @@ -87,7 +98,12 @@ region=[0, 10, -1.5, 1.5], projection="X10c", # Use "\\053" to handle "+b" as a string not as a modifier - frame=["wSnE+tbounds \\053b", "xa2f1", "ya1f0.1"], + frame=Frame( + axes="wSnE", + title="bounds \\053b", + xaxis=Axis(annot=2, tick=1), + yaxis=Axis(annot=1, tick=0.1), + ), ) # Plot an envelope based on the bounds ("+b") diff --git a/examples/gallery/lines/hlines_vlines.py b/examples/gallery/lines/hlines_vlines.py index 96b6e07b019..72960e3aa99 100644 --- a/examples/gallery/lines/hlines_vlines.py +++ b/examples/gallery/lines/hlines_vlines.py @@ -12,12 +12,14 @@ # In Cartesian coordinate systems lines are plotted as straight lines. import pygmt -from pygmt.params import Box, Position +from pygmt.params import Axis, Box, Frame, Position fig = pygmt.Figure() fig.basemap( - region=[0, 10, 0, 10], projection="X10c/10c", frame=["+tCartesian hlines", "af"] + region=[0, 10, 0, 10], + projection="X10c/10c", + frame=Frame(title="Cartesian hlines", axis=Axis(annot=True, tick=True)), ) # Add a horizontal line at y=9 @@ -37,7 +39,9 @@ fig.shift_origin(xshift="w+2c") fig.basemap( - region=[0, 10, 0, 10], projection="X10c/10c", frame=["+tCartesian vlines", "af"] + region=[0, 10, 0, 10], + projection="X10c/10c", + frame=Frame(title="Cartesian vlines", axis=Axis(annot=True, tick=True)), ) # Add a vertical line at x=1 fig.vlines(x=1, pen="1.5p,red3", label="Line 1") @@ -64,7 +68,11 @@ fig = pygmt.Figure() -fig.basemap(region="g", projection="R15c", frame=["+tGeographic hlines", "af"]) +fig.basemap( + region="g", + projection="R15c", + frame=Frame(title="Geographic hlines", axis=Axis(annot=True, tick=True)), +) # Add a line at 70°N fig.hlines(y=70, pen="1.5p,red3", label="Line 1") # Add a line at 50°N with longitude limits at 20°E and 160°E @@ -75,7 +83,11 @@ fig.shift_origin(xshift="w+2c") -fig.basemap(region="g", projection="R15c", frame=["+tGeographic vlines", "af"]) +fig.basemap( + region="g", + projection="R15c", + frame=Frame(title="Geographic vlines", axis=Axis(annot=True, tick=True)), +) # Add a line at 70°E fig.vlines(x=70, pen="1.5p,red3", label="Line 1") # Add a line at 20°E with latitude limits at 50°S and 70°N @@ -95,7 +107,11 @@ fig = pygmt.Figure() -fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+tPolar hlines", "af"]) +fig.basemap( + region=[0, 360, 0, 1], + projection="P10c", + frame=Frame(title="Polar hlines", axis=Axis(annot=True, tick=True)), +) # Add a line along radius=0.8 fig.hlines(y=0.8, pen="1.5p,red3", label="Line 1") # Add a line along radius=0.5 with azimuth limits at 30° and 160° @@ -106,7 +122,11 @@ fig.shift_origin(xshift="w+2c") -fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+tPolar vlines", "af"]) +fig.basemap( + region=[0, 360, 0, 1], + projection="P10c", + frame=Frame(title="Polar vlines", axis=Axis(annot=True, tick=True)), +) # Add a line along azimuth=120° fig.vlines(x=120, pen="1.5p,red3", label="Line 1") # Add a line along azimuth=190° with radius limits at 0.2 and 0.8 diff --git a/examples/gallery/lines/line_custom_cpt.py b/examples/gallery/lines/line_custom_cpt.py index a1a45920fe0..274b45aaf39 100644 --- a/examples/gallery/lines/line_custom_cpt.py +++ b/examples/gallery/lines/line_custom_cpt.py @@ -15,12 +15,15 @@ # %% import numpy as np import pygmt +from pygmt.params import Axis, Frame # Create a list of values between 20 and 30 with 0.2 intervals x = np.arange(start=20, stop=30, step=0.2) fig = pygmt.Figure() -fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10]) +fig.basemap( + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), region=[20, 30, -10, 10] +) # Create a custom CPT with the batlow CPT and 10 discrete z-values (colors), # use color_model="+c0-9" to write the color palette in categorical format and diff --git a/examples/gallery/lines/wiggle.py b/examples/gallery/lines/wiggle.py index 22393499c02..586a394386b 100644 --- a/examples/gallery/lines/wiggle.py +++ b/examples/gallery/lines/wiggle.py @@ -12,7 +12,7 @@ # %% import numpy as np import pygmt -from pygmt.params import Position +from pygmt.params import Axis, Frame, Position # Create (x, y, z) triplets x = np.arange(-7, 7, 0.1) @@ -20,7 +20,11 @@ z = 50 * np.exp(-((x / 3) ** 2)) * np.cos(2 * np.pi * x) fig = pygmt.Figure() -fig.basemap(region=[-8, 12, -1, 1], projection="X10c", frame=["Snlr", "xa2f1"]) +fig.basemap( + region=[-8, 12, -1, 1], + projection="X10c", + frame=Frame(axes="Snlr", xaxis=Axis(annot=2, tick=1)), +) fig.wiggle( x=x, y=y, diff --git a/examples/gallery/seismology/velo_arrow_ellipse.py b/examples/gallery/seismology/velo_arrow_ellipse.py index 6db53b7ecde..5fd2cff95bc 100644 --- a/examples/gallery/seismology/velo_arrow_ellipse.py +++ b/examples/gallery/seismology/velo_arrow_ellipse.py @@ -13,6 +13,7 @@ # %% import pandas as pd import pygmt +from pygmt.params import Axis, Frame fig = pygmt.Figure() df = pd.DataFrame( @@ -31,7 +32,7 @@ data=df, region=[-10, 8, -10, 6], projection="x0.8c", - frame=["WSne", "2g2f"], + frame=Frame(axes="WSne", axis=Axis(annot=2, grid=2, tick=True)), spec="e0.2/0.39+f18", uncertainty_fill="lightblue1", pen="0.6p,red", diff --git a/examples/gallery/symbols/datetime_inputs.py b/examples/gallery/symbols/datetime_inputs.py index 8fb975d947b..6d564a6f02a 100644 --- a/examples/gallery/symbols/datetime_inputs.py +++ b/examples/gallery/symbols/datetime_inputs.py @@ -28,6 +28,7 @@ import pandas as pd import pygmt import xarray as xr +from pygmt.params import Axis, Frame fig = pygmt.Figure() @@ -36,7 +37,7 @@ fig.basemap( projection="X15c/5c", region=[datetime.date(2010, 1, 1), datetime.date(2020, 6, 1), 0, 10], - frame=["WSen", "af"], + frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True)), ) # numpy.datetime64 types diff --git a/examples/gallery/symbols/multi_parameter_symbols.py b/examples/gallery/symbols/multi_parameter_symbols.py index 72480aba063..4dae9d60375 100644 --- a/examples/gallery/symbols/multi_parameter_symbols.py +++ b/examples/gallery/symbols/multi_parameter_symbols.py @@ -16,6 +16,7 @@ # %% import pygmt +from pygmt.params import Axis, Frame # %% # We can plot multi-parameter symbols using the same symbol style. We need to define @@ -70,7 +71,11 @@ # arguments are directions given in degrees counter-clockwise from horizontal fig = pygmt.Figure() -fig.basemap(region=[0, 7, 0, 4], projection="x3c", frame=["xa1f0.2", "ya0.5f0.1"]) +fig.basemap( + region=[0, 7, 0, 4], + projection="x3c", + frame=Frame(xaxis=Axis(annot=1, tick=0.2), yaxis=Axis(annot=0.5, tick=0.1)), +) # Ellipse data = [[0.5, 1, 45, 3, 1], [0.5, 3, 135, 2, 1]] diff --git a/examples/gallery/symbols/points_categorical.py b/examples/gallery/symbols/points_categorical.py index d9098b29871..6278e6c9167 100644 --- a/examples/gallery/symbols/points_categorical.py +++ b/examples/gallery/symbols/points_categorical.py @@ -15,6 +15,7 @@ # %% import pandas as pd import pygmt +from pygmt.params import Axis, Frame # Load sample penguins data df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv") @@ -51,11 +52,12 @@ fig.basemap( region=region, projection="X10c/10c", - frame=[ - "xafg+lBill length (mm)", - "yafg+lBill depth (mm)", - "WSen+tPenguin size at Palmer Station", - ], + frame=Frame( + axes="WSen", + title="Penguin size at Palmer Station", + xaxis=Axis(annot=True, tick=True, grid=True, label="Bill length (mm)"), + yaxis=Axis(annot=True, tick=True, grid=True, label="Bill depth (mm)"), + ), ) # Define a colormap for three categories, define the range of the diff --git a/examples/gallery/symbols/points_transparency.py b/examples/gallery/symbols/points_transparency.py index 8b6e8299e51..790f51f748d 100644 --- a/examples/gallery/symbols/points_transparency.py +++ b/examples/gallery/symbols/points_transparency.py @@ -9,6 +9,7 @@ # %% import numpy as np import pygmt +from pygmt.params import Axis, Frame # prepare the input x and y data x = np.arange(0, 105, 5) @@ -19,7 +20,10 @@ fig = pygmt.Figure() fig.basemap( region=[-5, 105, 0, 2], - frame=["xaf+lTransparency level+u%", "WSrt"], + frame=Frame( + axes="WSrt", + xaxis=Axis(annot=True, tick=True, label="Transparency level", unit="%"), + ), projection="X15c/6c", ) fig.plot(x=x, y=y, style="c0.6c", fill="blue", pen="1p,red", transparency=transparency) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index c62575c4852..e0f12b72958 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -12,6 +12,7 @@ # %% import numpy as np import pygmt +from pygmt.params import Axis, Frame rng = np.random.default_rng(seed=19680801) n = 200 # number of random data points @@ -20,7 +21,11 @@ fig.basemap( region=[-1, 1, -1, 1], projection="X10c/10c", - frame=["xa0.5fg", "ya0.5fg", "WSrt"], + frame=Frame( + axes="WSrt", + xaxis=Axis(annot=0.5, tick=True, grid=True), + yaxis=Axis(annot=0.5, tick=True, grid=True), + ), ) for fill in ["gray73", "darkorange", "slateblue"]: # Generate standard normal distributions centered on 0 diff --git a/examples/projections/nongeo/cartesian_linear.py b/examples/projections/nongeo/cartesian_linear.py index 7f9c6ebd43c..1e92966d2d4 100644 --- a/examples/projections/nongeo/cartesian_linear.py +++ b/examples/projections/nongeo/cartesian_linear.py @@ -19,10 +19,15 @@ # %% import pygmt +from pygmt.params import Axis, Frame fig = pygmt.Figure() # The region parameter is specified as xmin, xmax, ymin, ymax -fig.basemap(region=[0, 10, 0, 50], projection="X15c/10c", frame=["afg", "+gbisque"]) +fig.basemap( + region=[0, 10, 0, 50], + projection="X15c/10c", + frame=Frame(fill="bisque", axis=Axis(annot=True, tick=True, grid=True)), +) fig.plot(x=[3, 9, 2], y=[4, 9, 37], pen="2p,black") # Plot data points on top of the line # Use squares with a size of 0.3 centimeters, an "orange" fill and a "black" outline diff --git a/examples/projections/nongeo/cartesian_logarithmic.py b/examples/projections/nongeo/cartesian_logarithmic.py index f69c47b0732..f612d18e245 100644 --- a/examples/projections/nongeo/cartesian_logarithmic.py +++ b/examples/projections/nongeo/cartesian_logarithmic.py @@ -13,6 +13,7 @@ # %% import numpy as np import pygmt +from pygmt.params import Axis, Frame # Create a list of x-values 0-100 xline = np.arange(0, 101) @@ -29,7 +30,12 @@ # Set a logarithmic transformation on the x-axis projection="X15cl/10c", # Set the figure's frame and color as well as annotations, ticks, and gridlines - frame=["WSne+gbisque", "xa2g3", "ya2f1g2"], + frame=Frame( + axes="WSne", + fill="bisque", + xaxis=Axis(annot=2, grid=3), + yaxis=Axis(annot=2, tick=1, grid=2), + ), ) # Set the line thickness to "2p", the color to "black", and the style to "dashed" diff --git a/examples/projections/nongeo/cartesian_power.py b/examples/projections/nongeo/cartesian_power.py index b5f856713ed..2b7195b4cc9 100644 --- a/examples/projections/nongeo/cartesian_power.py +++ b/examples/projections/nongeo/cartesian_power.py @@ -15,6 +15,7 @@ # %% import numpy as np import pygmt +from pygmt.params import Axis, Frame # Create a list of y-values 0-10 yvalues = np.arange(0, 11) @@ -28,7 +29,12 @@ projection="X15cp0.5/10c", # Set the figures frame as well as annotations and ticks # The "p" forces to show only square numbers as annotations of the x-axis - frame=["WSne+gbisque", "xfga1p", "ya2f1g"], + frame=Frame( + axes="WSne", + fill="bisque", + xaxis=Axis(annot="1p", tick=True, grid=True), + yaxis=Axis(annot=2, tick=1, grid=True), + ), ) # Set the line thickness to "thick" (equals "1p", i.e. 1 point) diff --git a/examples/projections/nongeo/polar.py b/examples/projections/nongeo/polar.py index 05f8820272f..3924b04dbad 100644 --- a/examples/projections/nongeo/polar.py +++ b/examples/projections/nongeo/polar.py @@ -48,6 +48,7 @@ # %% import pygmt +from pygmt.params import Axis, Frame fig = pygmt.Figure() @@ -61,7 +62,11 @@ # Set map width to 5 cm projection="P5c", # Set the frame and title; @^ allows for a line break within the title - frame=["xa45f", "+gbisque+tprojection='P5c' @^ region=[0, 360, 0, 1]"], + frame=Frame( + fill="bisque", + title="projection='P5c' @^ region=[0, 360, 0, 1]", + xaxis=Axis(annot=45, tick=True), + ), ) fig.shift_origin(xshift="w+3c") @@ -75,7 +80,11 @@ # standard angle projection="P5c+a", # Set the frame and title; @^ allows for a line break within the title - frame=["xa45f", "+gbisque+tprojection='P5c+a' @^ region=[0, 360, 0, 1]"], + frame=Frame( + fill="bisque", + title="projection='P5c+a' @^ region=[0, 360, 0, 1]", + xaxis=Axis(annot=45, tick=True), + ), ) fig.shift_origin(xshift="w+3c") @@ -89,7 +98,13 @@ # standard angle projection="P5c+a", # Set the frame and title; @^ allows for a line break within the title - frame=["xa45f", "ya0.2", "WNe+gbisque+tprojection='P5c+a' @^ region=[0, 90, 0, 1]"], + frame=Frame( + axes="WNe", + fill="bisque", + title="projection='P5c+a' @^ region=[0, 90, 0, 1]", + xaxis=Axis(annot=45, tick=True), + yaxis=Axis(annot=0.2), + ), ) fig.shift_origin(xshift="-2w-6c", yshift="-h-2c") @@ -103,11 +118,13 @@ # standard angle, rotate coordinate system counterclockwise by 45 degrees projection="P5c+a+t45", # Set the frame and title; @^ allows for a line break within the title - frame=[ - "xa30f", - "ya0.2", - "WNe+gbisque+tprojection='P5c+a+t45' @^ region=[0, 90, 0, 1]", - ], + frame=Frame( + axes="WNe", + fill="bisque", + title="projection='P5c+a+t45' @^ region=[0, 90, 0, 1]", + xaxis=Axis(annot=30, tick=True), + yaxis=Axis(annot=0.2), + ), ) fig.shift_origin(xshift="w+3c", yshift="1.3c") @@ -122,11 +139,13 @@ # standard angle, rotate coordinate system counterclockwise by 45 degrees projection="P5c+a+t45", # Set the frame, and title; @^ allows for a line break within the title - frame=[ - "xa30f", - "ya", - "WNse+gbisque+tprojection='P5c+a+t45' @^ region=[0, 90, 3480, 6371]", - ], + frame=Frame( + axes="WNse", + fill="bisque", + title="projection='P5c+a+t45' @^ region=[0, 90, 3480, 6371]", + xaxis=Axis(annot=30, tick=True), + yaxis=Axis(annot=True), + ), ) fig.shift_origin(xshift="w+3c") @@ -142,11 +161,13 @@ # is marked as depth projection="P5c+a+t45+z", # Set the frame, and title; @^ allows for a line break within the title - frame=[ - "xa30f", - "ya", - "WNse+gbisque+tprojection='P5c+a+t45+\\z' @^ region=[0, 90, 3480, 6371]", - ], + frame=Frame( + axes="WNse", + fill="bisque", + title="projection='P5c+a+t45+\\z' @^ region=[0, 90, 3480, 6371]", + xaxis=Axis(annot=30, tick=True), + yaxis=Axis(annot=True), + ), ) fig.show() diff --git a/examples/tutorials/advanced/3d_perspective_image.py b/examples/tutorials/advanced/3d_perspective_image.py index aec98b5b9fe..0dc70274028 100644 --- a/examples/tutorials/advanced/3d_perspective_image.py +++ b/examples/tutorials/advanced/3d_perspective_image.py @@ -8,6 +8,7 @@ # %% import pygmt +from pygmt.params import Axis, Frame # Load sample earth relief data grid = pygmt.datasets.load_earth_relief(resolution="10m", region=[-108, -103, 35, 40]) @@ -28,7 +29,7 @@ # degrees perspective=[130, 30], # Sets the x- and y-axis labels, and annotates the west, south, and east axes - frame=["xa", "ya", "WSnE"], + frame=Frame(axes="WSnE", xaxis=Axis(annot=True), yaxis=Axis(annot=True)), # Sets a Mercator projection on a 15-centimeter figure projection="M15c", # Sets the height of the three-dimensional relief at 1.5 centimeters @@ -44,7 +45,7 @@ fig.grdview( grid=grid, perspective=[130, 30], - frame=["xa", "yaf", "WSnE"], + frame=Frame(axes="WSnE", xaxis=Axis(annot=True), yaxis=Axis(annot=True, tick=True)), projection="M15c", zsize="1.5c", surftype="surface", @@ -60,7 +61,7 @@ fig.grdview( grid=grid, perspective=[130, 30], - frame=["xa", "yaf", "WSnE"], + frame=Frame(axes="WSnE", xaxis=Axis(annot=True), yaxis=Axis(annot=True, tick=True)), projection="M15c", zsize="1.5c", surftype="surface", @@ -83,7 +84,11 @@ grid=grid, # Set the azimuth to -130 (230) degrees and the elevation to 30 degrees perspective=[-130, 30], - frame=["xaf", "yaf", "WSnE"], + frame=Frame( + axes="WSnE", + xaxis=Axis(annot=True, tick=True), + yaxis=Axis(annot=True, tick=True), + ), projection="M15c", zsize="1.5c", surftype="surface", diff --git a/examples/tutorials/advanced/cartesian_histograms.py b/examples/tutorials/advanced/cartesian_histograms.py index 5b66707befd..79beb5eec44 100644 --- a/examples/tutorials/advanced/cartesian_histograms.py +++ b/examples/tutorials/advanced/cartesian_histograms.py @@ -18,7 +18,7 @@ # Import the required packages import numpy as np import pygmt -from pygmt.params import Pattern +from pygmt.params import Axis, Frame, Pattern # %% # Generate random data from a normal distribution: @@ -55,7 +55,11 @@ projection="X10c", # Cartesian projection with a width of 10 centimeters # Add frame, annotations ("a"), ticks ("f"), and y-axis label ("+l") "Counts"; the # numbers give the steps of annotations and ticks - frame=["WStr", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WStr", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data01, # Set the bin width via the "series" parameter series=10, @@ -74,7 +78,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WStr", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WStr", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data01, series=10, fill="red3", @@ -101,7 +109,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSne", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data01, series=10, # Draw a 1-point thick, dotted outline in "red3" @@ -117,7 +129,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSne", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data02, series=10, # Draw a 1.5-point thick, dashed outline in "orange" @@ -143,7 +159,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSnr", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WSnr", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data02, series=10, fill="orange", @@ -159,7 +179,11 @@ region=[0, 200, 0, 0], projection="X10c", # Add suffix % (+u) - frame=["lSnE", "xaf10", "ya2f1+u%+lFrequency percent"], + frame=Frame( + axes="lSnE", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=2, tick=1, unit="%", label="Frequency percent"), + ), data=data02, series=10, fill="orange", @@ -186,7 +210,11 @@ fig.histogram( region=[0, 200, 0, len(data01) + 1], projection="X10c", - frame=["WSne", "xaf10", "ya5f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=5, tick=1, label="Counts"), + ), data=data01, series=10, fill="red3", @@ -202,7 +230,11 @@ fig.histogram( region=[0, 200, 0, len(data01) + 1], projection="X10c", - frame=["wSnE", "xaf10", "ya5f1+lCumulative counts"], + frame=Frame( + axes="wSnE", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=5, tick=1, label="Cumulative counts"), + ), data=data01, series=10, # Fill bars with GMT pattern 8, with white background and black foreground. @@ -238,7 +270,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSne", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data01, series=10, fill="red3", @@ -289,7 +325,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSne", "xaf10", "ya1f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data_merge, series=10, fill="orange", @@ -337,7 +377,11 @@ fig.histogram( region=[0, 200, 0, 0], projection="X10c", - frame=["WSne", "xaf10g10", "ya1f1+lCounts"], + frame=Frame( + axes="WSne", + xaxis=Axis(annot=True, tick=10, grid=10), + yaxis=Axis(annot=1, tick=1, label="Counts"), + ), data=data01, series=binwidth, fill="red3", diff --git a/examples/tutorials/advanced/date_time_charts.py b/examples/tutorials/advanced/date_time_charts.py index d198b3c7d70..0f650a5aac3 100644 --- a/examples/tutorials/advanced/date_time_charts.py +++ b/examples/tutorials/advanced/date_time_charts.py @@ -19,6 +19,7 @@ import pandas as pd import pygmt import xarray as xr +from pygmt.params import Axis, Frame # %% # Using Python's ``datetime`` @@ -42,7 +43,7 @@ fig.plot( projection="X10c/5c", region=[datetime.date(2010, 1, 1), datetime.date(2014, 12, 1), 0, 6], - frame=["WSen", "afg"], + frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=x, y=y, style="c0.3c", @@ -79,7 +80,7 @@ 0, 6, ], - frame=["WS", "af"], + frame=Frame(axes="WS", axis=Axis(annot=True, tick=True)), x=x, y=y, style="c0.4c", @@ -112,7 +113,7 @@ fig.plot( projection="X10c/5c", region=["2016-01-01", "2017-01-01", 0, 6], - frame=["WSen", "afg"], + frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=x, y=y, style="a0.45c", @@ -145,7 +146,7 @@ fig.plot( projection="X10c/5c", region=[datetime.datetime(2020, 1, 1), datetime.datetime(2021, 3, 1), 0, 6], - frame=["WSen", "afg"], + frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=x, y=y, style="i0.4c", @@ -175,7 +176,7 @@ fig.plot( projection="X10c/10c", region=[datetime.datetime(2017, 12, 31), datetime.datetime(2019, 12, 31), 0, 10], - frame=["WSen", "ag"], + frame=Frame(axes="WSen", axis=Axis(annot=True, grid=True)), x=x, y=y, style="i0.4c", @@ -203,7 +204,7 @@ fig.plot( projection="X10c/10c", region=[datetime.datetime(2020, 1, 1), datetime.datetime(2021, 4, 1), 0, 10], - frame=["WSen", "ag"], + frame=Frame(axes="WSen", axis=Axis(annot=True, grid=True)), x=x, y=y, style="n0.4c", @@ -231,7 +232,7 @@ fig.plot( projection="X10c/10c", region=[datetime.datetime(2010, 1, 1), datetime.datetime(2012, 6, 1), 0, 10], - frame=["WS", "ag"], + frame=Frame(axes="WS", axis=Axis(annot=True, grid=True)), x=x, y=y, style="s0.5c", @@ -270,7 +271,7 @@ fig.plot( region=region, projection="X15c/10c", - frame=["WSen", "afg"], + frame=Frame(axes="WSen", axis=Axis(annot=True, tick=True, grid=True)), x=df.Date, y=df.Score, style="c0.4c", @@ -286,20 +287,19 @@ # # This example focuses on annotating the axes and setting the interval in which the # annotations should appear. All of these modifications are passed to the ``frame`` -# parameter and each item in that list modifies a specific aspect of the frame. +# parameter via a :class:`pygmt.params.Frame` object. # -# Adding ``"WS"`` means that only the Western/Left (**W**) and Southern/Bottom (**S**) -# borders of the plot are annotated. For more information on this, please refer to the +# Setting ``axes="WS"`` in :class:`pygmt.params.Frame` means that only the +# Western/Left (**W**) and Southern/Bottom (**S**) borders of the plot are annotated. +# For more information on this, please refer to the # :doc:`Frames, ticks, titles, and labels tutorial `. # -# Another important item in the list passed to ``frame`` is ``"sxa1Of1D"``. This string -# modifies the secondary annotation (**s**) of the x-axis (**x**). Specifically, it sets -# the main annotation and major tick spacing interval to one month (**a1O**) (capital -# letter O, not zero). Additionally, it sets the minor tick spacing interval to 1 day -# (**f1D**). To use the month name instead of its number set :gmt-term:`FORMAT_DATE_MAP` -# to **o**. More information on configuring date formats can be found at -# :gmt-term:`FORMAT_DATE_MAP`, :gmt-term:`FORMAT_DATE_IN`, and -# :gmt-term:`FORMAT_DATE_OUT`. +# Setting ``xaxis2=Axis(annot="1O", tick="1D")`` modifies the secondary x-axis +# annotation interval to one month (**1O**) (capital letter O, not zero), and sets the +# minor tick spacing interval to 1 day (**1D**). To use the month name instead of its +# number set :gmt-term:`FORMAT_DATE_MAP` to **o**. More information on configuring +# date formats can be found at :gmt-term:`FORMAT_DATE_MAP`, :gmt-term:`FORMAT_DATE_IN`, +# and :gmt-term:`FORMAT_DATE_OUT`. x = pd.date_range("2013-05-02", periods=10, freq="2D") y = [4, 5, 6, 8, 9, 5, 8, 9, 4, 2] @@ -309,7 +309,13 @@ fig.plot( projection="X15c/10c", region=[datetime.datetime(2013, 5, 1), datetime.datetime(2013, 5, 25), 0, 10], - frame=["WS", "sxa1Of1D", "pxa5d", "sy+lLength", "pya1+ucm"], + frame=Frame( + axes="WS", + xaxis=Axis(annot="5d"), + yaxis=Axis(annot=1, unit="cm"), + xaxis2=Axis(annot="1O", tick="1D"), + yaxis2=Axis(label="Length"), + ), x=x, y=y, style="c0.4c", @@ -344,7 +350,13 @@ 0, 10, ], - frame=["WS", "sxa1K", "pxa6H", "sy+lSpeed", "pya1+ukm/h"], + frame=Frame( + axes="WS", + xaxis=Axis(annot="6H"), + yaxis=Axis(annot=1, unit="km/h"), + xaxis2=Axis(annot="1K"), + yaxis2=Axis(label="Speed"), + ), x=x, y=y, style="n0.4c", diff --git a/examples/tutorials/advanced/grid_equalization.py b/examples/tutorials/advanced/grid_equalization.py index 09e0beaefe8..f0ed159d8ea 100644 --- a/examples/tutorials/advanced/grid_equalization.py +++ b/examples/tutorials/advanced/grid_equalization.py @@ -8,7 +8,7 @@ # %% import pygmt -from pygmt.params import Frame, Position +from pygmt.params import Axis, Frame, Position # %% # Load sample data @@ -52,7 +52,11 @@ projection="X?", region=[500, 3600, 0, 20], series=[500, 3600, 100], - frame=["wnSE", "xaf+lElevation (m)", "yaf+lPercent frequency"], + frame=Frame( + axes="wnSE", + xaxis=Axis(annot=True, tick=True, label="Elevation (m)"), + yaxis=Axis(annot=True, tick=True, label="Percent frequency"), + ), cmap=True, histtype=1, pen="1p,black", @@ -125,7 +129,11 @@ projection="X?", region=[-1, divisions, 0, 40], series=[0, divisions, 1], - frame=["wnSE", "xaf+lRelative elevation", "yaf+lPercent frequency"], + frame=Frame( + axes="wnSE", + xaxis=Axis(annot=True, tick=True, label="Relative elevation"), + yaxis=Axis(annot=True, tick=True, label="Percent frequency"), + ), cmap=True, histtype=1, pen="1p,black", @@ -180,7 +188,11 @@ projection="X?", region=[-4.5, 4.5, 0, 20], series=[-4.5, 4.5, 0.2], - frame=["wnSE", "xaf+lRelative elevation", "yaf+lPercent frequency"], + frame=Frame( + axes="wnSE", + xaxis=Axis(annot=True, tick=True, label="Relative elevation"), + yaxis=Axis(annot=True, tick=True, label="Percent frequency"), + ), cmap=True, histtype=1, pen="1p,black", @@ -251,7 +263,11 @@ projection="X?", region=[-1, divisions, 0, 40], series=[0, divisions, 1], - frame=["wnSE", "xaf+lRelative elevation", "yaf+lPercent frequency"], + frame=Frame( + axes="wnSE", + xaxis=Axis(annot=True, tick=True, label="Relative elevation"), + yaxis=Axis(annot=True, tick=True, label="Percent frequency"), + ), cmap=True, histtype=1, pen="1p,black", diff --git a/examples/tutorials/advanced/non_ascii_text.py b/examples/tutorials/advanced/non_ascii_text.py index fb88c50e46f..a3f339a8a42 100644 --- a/examples/tutorials/advanced/non_ascii_text.py +++ b/examples/tutorials/advanced/non_ascii_text.py @@ -23,12 +23,18 @@ # %% import pygmt +from pygmt.params import Axis, Frame fig = pygmt.Figure() fig.basemap( region=[0, 5, 0, 6], projection="X14c/7c", - frame=["xaf+lDistance (°)", "yaf+lValue (‰)", "WSen+tTitle: α² ± β²"], + frame=Frame( + axes="WSen", + title="Title: α² ± β²", + xaxis=Axis(annot=True, tick=True, label="Distance (°)"), + yaxis=Axis(annot=True, tick=True, label="Value (‰)"), + ), ) fig.text( diff --git a/examples/tutorials/advanced/subplots.py b/examples/tutorials/advanced/subplots.py index 4a19f177def..628adc727e0 100644 --- a/examples/tutorials/advanced/subplots.py +++ b/examples/tutorials/advanced/subplots.py @@ -20,7 +20,7 @@ # %% import pygmt -from pygmt.params import Frame +from pygmt.params import Axis, Frame # %% # Let's start by initializing a :class:`pygmt.Figure` instance. @@ -106,7 +106,7 @@ ncols=2, figsize=("15c", "6c"), tag=True, - frame=["af", "WSne"], + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), margins=["0.1c", "0.2c"], title="My Subplot Heading", ): @@ -207,17 +207,26 @@ # Bottom row, two subplots with fig.subplot(nrows=1, ncols=2, figsize=("15c", "3c"), tag="b)"): fig.basemap( - region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[0, 0] + region=[0, 5, 0, 5], + projection="X?", + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), + panel=[0, 0], ) fig.basemap( - region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[0, 1] + region=[0, 5, 0, 5], + projection="X?", + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), + panel=[0, 1], ) # Move plot origin by 1 cm above the height of the entire figure fig.shift_origin(yshift="h+1c") # Top row, one subplot with fig.subplot(nrows=1, ncols=1, figsize=("15c", "3c"), tag="a)"): fig.basemap( - region=[0, 10, 0, 10], projection="X?", frame=["af", "WSne"], panel=[0, 0] + region=[0, 10, 0, 10], + projection="X?", + frame=Frame(axes="WSne", axis=Axis(annot=True, tick=True)), + panel=[0, 0], ) fig.text(text="TEXT", x=5, y=5) diff --git a/examples/tutorials/basics/text.py b/examples/tutorials/basics/text.py index 9e4a5857f77..afe05353ff5 100644 --- a/examples/tutorials/basics/text.py +++ b/examples/tutorials/basics/text.py @@ -197,7 +197,11 @@ # ----------------------------------------------------------------------------- # Left: Add a tag to a subplot -fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=["WStr", "af"]) +fig.basemap( + region=[-5, 5, -5, 5], + projection="X5c", + frame=Frame(axes="WStr", axis=Axis(annot=True, tick=True)), +) fig.text( text="(a)", @@ -210,7 +214,11 @@ # ----------------------------------------------------------------------------- # Right: Add a text label outside of the plot or map frame -fig.basemap(region=[-30, 30, 10, 60], projection="L0/35/23/47/5c", frame=["wSnE", "af"]) +fig.basemap( + region=[-30, 30, 10, 60], + projection="L0/35/23/47/5c", + frame=Frame(axes="wSnE", axis=Axis(annot=True, tick=True)), +) fig.text( text="@@100 km", # "@@" gives "@" in GMT or PyGMT diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index dad621f71c9..1b2820612b0 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -38,6 +38,7 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag >>> import pytest >>> import shutil >>> from pygmt import Figure + >>> from pygmt.params import Axis, Frame >>> from pathlib import Path >>> @check_figures_equal(result_dir="tmp_result_images") @@ -46,7 +47,9 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag ... fig_ref.basemap(projection="X5c", region=[0, 5, 0, 5], frame=True) ... fig_test = Figure() ... fig_test.basemap( - ... projection="X5c", region=[0, 5, 0, 5], frame=["WrStZ", "af"] + ... projection="X5c", + ... region=[0, 5, 0, 5], + ... frame=Frame(axes="WrStZ", axis=Axis(annot=True, tick=True)), ... ) ... return fig_ref, fig_test >>> test_check_figures_equal() diff --git a/pygmt/src/colorbar.py b/pygmt/src/colorbar.py index 9d9f1261d79..b00761f92f6 100644 --- a/pygmt/src/colorbar.py +++ b/pygmt/src/colorbar.py @@ -47,6 +47,16 @@ def _build_frame( ['xa1f0.5g0.2+lDistance+a30', 'y+lkm'] >>> list(_build_frame(frame=["xaf0.5+lDistance", "y+lkm"])) ['xaf0.5+lDistance', 'y+lkm'] + >>> from pygmt.params import Axis, Frame + >>> list( + ... _build_frame( + ... frame=Frame( + ... xaxis=Axis(annot=True, tick=0.5, label="Distance"), + ... yaxis=Axis(label="km"), + ... ) + ... ) + ... ) + ['xaf0.5+lDistance', 'y+lkm'] >>> _build_frame(frame="none") 'none' diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 228f193ca00..0cf823d7b59 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -255,6 +255,7 @@ def grdview( # noqa: PLR0913 Example ------- >>> import pygmt + >>> from pygmt.params import Axis, Frame >>> # Load the 30 arc-minutes grid with "gridline" registration in a given region >>> grid = pygmt.datasets.load_earth_relief( ... resolution="30m", @@ -271,7 +272,7 @@ def grdview( # noqa: PLR0913 ... perspective=[130, 30], ... # Add a frame to the x- and y-axes ... # Specify annotations on the south and east borders of the plot - ... frame=["xa", "ya", "wSnE"], + ... frame=Frame(axes="wSnE", xaxis=Axis(annot=True), yaxis=Axis(annot=True)), ... # Set the projection of the 2-D map to Mercator with a 10 cm width ... projection="M10c", ... # Set the vertical scale (z-axis) to 2 cm diff --git a/pygmt/tests/test_basemap.py b/pygmt/tests/test_basemap.py index 24146e12a0e..238d4648617 100644 --- a/pygmt/tests/test_basemap.py +++ b/pygmt/tests/test_basemap.py @@ -4,7 +4,7 @@ import pytest from pygmt import Figure -from pygmt.params import Axis +from pygmt.params import Axis, Frame @pytest.mark.benchmark @@ -31,7 +31,11 @@ def test_basemap_loglog(): fig.basemap( region=[1, 10000, 1e20, 1e25], projection="X16cl/12cl", - frame=["WS", "x2+lWavelength", "ya1pf3+lPower"], + frame=Frame( + axes="WS", + xaxis=Axis(annot=2, label="Wavelength"), + yaxis=Axis(annot="1p", tick=3, label="Power"), + ), ) return fig @@ -45,7 +49,10 @@ def test_basemap_power_axis(): fig.basemap( region=[0, 100, 0, 5000], projection="x1p0.5/-0.001", - frame=["x1p+lCrustal age", "y500+lDepth"], + frame=Frame( + xaxis=Axis(annot="1p", label="Crustal age"), + yaxis=Axis(annot=500, label="Depth"), + ), ) return fig diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py index 6a8c9bf3529..dd556e9bd15 100644 --- a/pygmt/tests/test_config.py +++ b/pygmt/tests/test_config.py @@ -4,6 +4,7 @@ import pytest from pygmt import Figure, config +from pygmt.params import Axis, Frame @pytest.mark.mpl_image_compare @@ -15,7 +16,9 @@ def test_config(): # Change global settings of current figure config(FONT_ANNOT_PRIMARY="blue") fig.basemap( - region=[0, 10, 0, 10], projection="X5c/5c", frame=["af", "+tBlue Annotation"] + region=[0, 10, 0, 10], + projection="X5c/5c", + frame=Frame(title="Blue Annotation", axis=Axis(annot=True, tick=True)), ) with config(FONT_LABEL="red", FONT_ANNOT_PRIMARY="red"): @@ -23,14 +26,18 @@ def test_config(): fig.basemap( region=[0, 10, 0, 10], projection="X5c/5c", - frame=["xaf+lred label", "yaf", "+tred annotation"], + frame=Frame( + title="red annotation", + xaxis=Axis(annot=True, tick=True, label="red label"), + yaxis=Axis(annot=True, tick=True), + ), ) fig.shift_origin(xshift="7c") fig.basemap( region=[0, 10, 0, 10], projection="X5c/5c", - frame=["af", "+tBlue Annotation"], + frame=Frame(title="Blue Annotation", axis=Axis(annot=True, tick=True)), ) # Revert to default settings in current figure config(FONT_ANNOT_PRIMARY="black") @@ -85,7 +92,7 @@ def test_config_format_date_map(): fig.basemap( region=["1969-7-21T", "1969-7-23T", 0, 1], projection="X2.5c/0.1c", - frame=["sxa1D", "S"], + frame=Frame(axes="S", xaxis2=Axis(annot="1D")), ) return fig diff --git a/pygmt/tests/test_geopandas.py b/pygmt/tests/test_geopandas.py index 5202b2804f9..fea14c4626a 100644 --- a/pygmt/tests/test_geopandas.py +++ b/pygmt/tests/test_geopandas.py @@ -9,6 +9,7 @@ from pygmt import Figure, info, makecpt, which from pygmt.helpers import data_kind from pygmt.helpers.testing import skip_if_no +from pygmt.params import Axis, Frame geopandas = pytest.importorskip("geopandas") shapely = pytest.importorskip("shapely") @@ -118,7 +119,12 @@ def test_geopandas_plot3d_default_cube(): perspective=[315, 25], region=[0, 2, 0, 2, 0, 2], projection="X2c", - frame=["WsNeZ1", "xag", "yag", "zag"], + frame=Frame( + axes="WsNeZ1", + xaxis=Axis(annot=True, grid=True), + yaxis=Axis(annot=True, grid=True), + zaxis=Axis(annot=True, grid=True), + ), zscale=1.5, ) return fig @@ -151,7 +157,12 @@ def test_geopandas_plot3d_non_default_circle(): perspective=[315, 25], region=[0, 2, 0, 2, 0, 2], projection="X2c", - frame=["WsNeZ1", "xag", "yag", "zag"], + frame=Frame( + axes="WsNeZ1", + xaxis=Axis(annot=True, grid=True), + yaxis=Axis(annot=True, grid=True), + zaxis=Axis(annot=True, grid=True), + ), zscale=1.5, style="c0.2c", ) diff --git a/pygmt/tests/test_grdview.py b/pygmt/tests/test_grdview.py index ede0fdb41f1..466a2c59666 100644 --- a/pygmt/tests/test_grdview.py +++ b/pygmt/tests/test_grdview.py @@ -7,6 +7,7 @@ from pygmt.exceptions import GMTParameterError, GMTTypeError from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief +from pygmt.params import Axis, Frame @pytest.fixture(scope="module", name="region") @@ -79,7 +80,9 @@ def test_grdview_image_dpi(grid): projection="M4c", surftype="image", dpi=dpi, - frame=["af", f"WSen+tdpi={dpi}"], + frame=Frame( + axes="WSen", title=f"dpi={dpi}", axis=Axis(annot=True, tick=True) + ), perspective=(225, 30), ) fig.shift_origin(xshift="7c") @@ -222,7 +225,11 @@ def test_grdview_with_perspective_and_zaxis_frame(xrgrid, region): projection=projection, perspective=[225, 30], zscale=0.005, - frame=["xaf", "yaf", "zaf"], + frame=Frame( + xaxis=Axis(annot=True, tick=True), + yaxis=Axis(annot=True, tick=True), + zaxis=Axis(annot=True, tick=True), + ), ) return fig