Skip to content

Commit

Permalink
Alias straight_lines(A), error_bars(E), close(L), position(D) for plot3d
Browse files Browse the repository at this point in the history
Added new aliases (mostly based on GMT.jl's), and fixed old docstring to remove short-form aliases. Since `plot3d` and `plot` are similar, we might as well fix both of them at the same time. Also keeping the unit tests consistent.
  • Loading branch information
weiji14 committed Jun 1, 2020
1 parent e38b3f9 commit e7f7679
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
87 changes: 52 additions & 35 deletions pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,17 @@ def grdview(self, grid, **kwargs):
@use_alias(
R="region",
J="projection",
A="straight_lines",
B="frame",
S="style",
C="cmap",
D="position",
E="error_bars",
G="color",
L="close",
S="style",
W="pen",
i="columns",
l="label",
C="cmap",
)
@kwargs_to_strings(R="sequence", i="sequence_comma")
def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
Expand All @@ -452,26 +456,26 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
Must provide either *data* or *x* and *y*.
If providing data through *x* and *y*, *color* (G) can be a 1d array
that will be mapped to a colormap.
If providing data through *x* and *y*, *color* can be a 1d array that
will be mapped to a colormap.
If a symbol is selected and no symbol size given, then psxy will
If a symbol is selected and no symbol size given, then plot will
interpret the third column of the input data as symbol size. Symbols
whose size is <= 0 are skipped. If no symbols are specified then the
symbol code (see *S* below) must be present as last column in the
input. If *S* is not used, a line connecting the data points will be
drawn instead. To explicitly close polygons, use *L*. Select a fill
with *G*. If *G* is set, *W* will control whether the polygon outline
is drawn or not. If a symbol is selected, *G* and *W* determines the
fill and outline/no outline, respectively.
symbol code (see *symbol* below) must be present as last column in the
input. If *symbol* is not used, a line connecting the data points will
be drawn instead. To explicitly close polygons, use *close*. Select a
fill with *color*. If *color* is set, *pen* will control whether the
polygon outline is drawn or not. If a symbol is selected, *color* and
*pen* determines the fill and outline/no outline, respectively.
Full option list at :gmt-docs:`plot.html`
{aliases}
Parameters
----------
x, y : float or 1d arrays
x/y : float or 1d arrays
The x and y coordinates, or arrays of x and y coordinates of the
data points
data : str or 2d array
Expand All @@ -488,25 +492,29 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
depending on the style options chosen.
{J}
{R}
A : bool or str
straight_lines : bool or str
``'[m|p|x|y]'``
By default, geographic line segments are drawn as great circle
arcs. To draw them as straight lines, use *A*.
arcs. To draw them as straight lines, use *straight_lines*.
{B}
{CPT}
D : str
position : str
``'dx/dy'``: Offset the plot symbol or line locations by the given
amounts dx/dy.
E : bool or str
error_bars : bool or str
``'[x|y|X|Y][+a][+cl|f][+n][+wcap][+ppen]'``.
Draw symmetrical error bars.
{G}
S : str
style : str
Plot symbols (including vectors, pie slices, fronts, decorated or
quoted lines).
{W}
{U}
l : str
columns : list or str
``cols[+l][+sscale][+ooffset][,…][,t[word]]``
Select input columns and transformations (0 is first column, t is
trailing text, append word to read one word only).
label : str
Add a legend entry for the symbol or line being plotted.
"""
kwargs = self._preprocess(**kwargs)
Expand Down Expand Up @@ -551,13 +559,17 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
J="projection",
Jz="zscale",
JZ="zsize",
A="straight_lines",
B="frame",
S="style",
C="cmap",
D="position",
E="error_bars",
G="color",
L="close",
S="style",
W="pen",
i="columns",
l="label",
C="cmap",
p="perspective",
)
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
Expand All @@ -567,23 +579,24 @@ def plot3d(
"""
Plot lines, polygons, and symbols in 3-D
Takes a matrix, (x,y,z) triplets, or a file name as input and plots lines,
polygons, or symbols at those locations in 3-D.
Takes a matrix, (x,y,z) triplets, or a file name as input and plots
lines, polygons, or symbols at those locations in 3-D.
Must provide either *data* or *x*, *y* and *z*.
#If providing data through *x* and *y*, *color* (G) can be a 1d array
#that will be mapped to a colormap.
If providing data through *x*, *y* and *z*, *color* can be a 1d array
that will be mapped to a colormap.
If a symbol is selected and no symbol size given, then plot3d will
interpret the fourth column of the input data as symbol size. Symbols
whose size is <= 0 are skipped. If no symbols are specified then the
symbol code (see *S* below) must be present as last column in the
input. If *S* is not used, a line connecting the data points will be
drawn instead. To explicitly close polygons, use *L*. Select a fill
with *G*. If *G* is set, *W* will control whether the polygon outline
is drawn or not. If a symbol is selected, *G* and *W* determines the
fill and outline/no outline, respectively.
symbol code (see *style* below) must be present as last column in the
input. If *style* is not used, a line connecting the data points will
be drawn instead. To explicitly close polygons, use *close*. Select a
fill
with *color*. If *color* is set, *pen* will control whether the polygon
outline is drawn or not. If a symbol is selected, *color* and *pen*
determines the fill and outline/no outline, respectively.
Full option list at :gmt-docs:`plot3d.html`
Expand All @@ -610,25 +623,29 @@ def plot3d(
zscale/zsize : float or str
Set z-axis scaling or z-axis size.
{R}
A : bool or str
straight_lines : bool or str
``'[m|p|x|y]'``
By default, geographic line segments are drawn as great circle
arcs. To draw them as straight lines, use *A*.
{B}
{CPT}
D : str
position : str
``'dx/dy'``: Offset the plot symbol or line locations by the given
amounts dx/dy.
E : bool or str
error_bars : bool or str
``'[x|y|X|Y][+a][+cl|f][+n][+wcap][+ppen]'``.
Draw symmetrical error bars.
{G}
S : str
style : str
Plot symbols (including vectors, pie slices, fronts, decorated or
quoted lines).
{W}
{U}
l : str
columns : list or str
``cols[+l][+sscale][+ooffset][,…][,t[word]]``
Select input columns and transformations (0 is first column, t is
trailing text, append word to read one word only).
label : str
Add a legend entry for the symbol or line being plotted.
perspective : list or str
``'[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]'``.
Expand Down
12 changes: 6 additions & 6 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,32 @@ def test_plot_colors_sizes_proj(data, region):


@pytest.mark.mpl_image_compare
def test_plot_matrix(data):
def test_plot_matrix(data, region):
"Plot the data passing in a matrix and specifying columns"
fig = Figure()
fig.plot(
data=data,
region=[10, 70, -5, 10],
region=region,
projection="M10i",
style="cc",
color="#aaaaaa",
B="a",
frame="a",
columns="0,1,2+s0.005",
)
return fig


@pytest.mark.mpl_image_compare
def test_plot_matrix_color(data):
def test_plot_matrix_color(data, region):
"Plot the data passing in a matrix and using a colormap"
fig = Figure()
fig.plot(
data=data,
region=[10, 70, -5, 10],
region=region,
projection="X5i",
style="c0.5c",
cmap="rainbow",
B="a",
frame="a",
)
return fig

Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_plot3d_matrix(data, region):
projection="M10i",
style="c1c",
color="#aaaaaa",
B=["a", "za"],
frame=["a", "za"],
columns="0,1,2",
)
return fig
Expand All @@ -242,7 +242,7 @@ def test_plot3d_matrix_color(data, region):
style="c0.5c",
cmap="rainbow",
columns=[0, 1, 2, 2],
B=["a", "za"],
frame=["a", "za"],
)
return fig

Expand Down

0 comments on commit e7f7679

Please sign in to comment.