Skip to content

Commit e0f8e84

Browse files
Figure.plot/Figure.plot3d: Improve the docstrings for straight_line (#3720)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 4c03bab commit e0f8e84

File tree

2 files changed

+66
-25
lines changed

2 files changed

+66
-25
lines changed

pygmt/src/plot.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
plot - Plot in two dimensions.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.clib import Session
68
from pygmt.exceptions import GMTInvalidInput
79
from pygmt.helpers import (
@@ -49,7 +51,15 @@
4951
)
5052
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
5153
def plot(
52-
self, data=None, x=None, y=None, size=None, symbol=None, direction=None, **kwargs
54+
self,
55+
data=None,
56+
x=None,
57+
y=None,
58+
size=None,
59+
symbol=None,
60+
direction=None,
61+
straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001
62+
**kwargs,
5363
):
5464
r"""
5565
Plot lines, polygons, and symbols in 2-D.
@@ -98,18 +108,29 @@ def plot(
98108
depending on the style options chosen.
99109
{projection}
100110
{region}
101-
straight_line : bool or str
102-
[**m**\|\ **p**\|\ **x**\|\ **y**].
103-
By default, geographic line segments are drawn as great circle
104-
arcs. To draw them as straight lines, use
105-
``straight_line=True``.
106-
Alternatively, add **m** to draw the line by first following a
107-
meridian, then a parallel. Or append **p** to start following a
108-
parallel, then a meridian. (This can be practical to draw a line
109-
along parallels, for example). For Cartesian data, points are
110-
simply connected, unless you append **x** or **y** to draw
111-
stair-case curves that whose first move is along *x* or *y*,
112-
respectively.
111+
straight_line
112+
By default, line segments are drawn as straight lines in the Cartesian and polar
113+
coordinate systems, and as great circle arcs (by resampling coarse input data
114+
along such arcs) in the geographic coordinate system. The ``straight_line``
115+
parameter can control the drawing of line segments. Valid values are:
116+
117+
- ``True``: Draw line segments as straight lines in geographic coordinate
118+
systems.
119+
- ``"x"``: Draw line segments by first along *x*, then along *y*.
120+
- ``"y"``: Draw line segments by first along *y*, then along *x*.
121+
122+
Here, *x* and *y* have different meanings depending on the coordinate system:
123+
124+
- **Cartesian** coordinate system: *x* and *y* are the X- and Y-axes.
125+
- **Polar** coordinate system: *x* and *y* are theta and radius.
126+
- **Geographic** coordinate system: *x* and *y* are parallels and meridians.
127+
128+
.. attention::
129+
130+
There exits a bug in GMT<=6.5.0 that, in geographic coordinate systems, the
131+
meaning of *x* and *y* is reversed, i.e., *x* means meridians and *y* means
132+
parallels. The bug is fixed by upstream
133+
`PR #8648 <https://github.com/GenericMappingTools/gmt/pull/8648>`__.
113134
{frame}
114135
{cmap}
115136
offset : str
@@ -206,6 +227,8 @@ def plot(
206227
``x``/``y``.
207228
{wrap}
208229
"""
230+
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
231+
# parameter.
209232
kwargs = self._preprocess(**kwargs)
210233

211234
kind = data_kind(data)

pygmt/src/plot3d.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
plot3d - Plot in three dimensions.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.clib import Session
68
from pygmt.exceptions import GMTInvalidInput
79
from pygmt.helpers import (
@@ -58,6 +60,7 @@ def plot3d(
5860
size=None,
5961
symbol=None,
6062
direction=None,
63+
straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001
6164
**kwargs,
6265
):
6366
r"""
@@ -108,18 +111,31 @@ def plot3d(
108111
zscale/zsize : float or str
109112
Set z-axis scaling or z-axis size.
110113
{region}
111-
straight_line : bool or str
112-
[**m**\|\ **p**\|\ **x**\|\ **y**].
113-
By default, geographic line segments are drawn as great circle
114-
arcs. To draw them as straight lines, use ``straight_line``.
115-
Alternatively, add **m** to draw the line by first following a
116-
meridian, then a parallel. Or append **p** to start following a
117-
parallel, then a meridian. (This can be practical to draw a line
118-
along parallels, for example). For Cartesian data, points are
119-
simply connected, unless you append **x** or **y** to draw
120-
stair-case curves that whose first move is along *x* or *y*,
121-
respectively. **Note**: The ``straight_line`` parameter requires
122-
constant *z*-coordinates.
114+
straight_line
115+
By default, line segments are drawn as straight lines in the Cartesian and polar
116+
coordinate systems, and as great circle arcs (by resampling coarse input data
117+
along such arcs) in the geographic coordinate system. The ``straight_line``
118+
parameter can control the drawing of line segments. Valid values are:
119+
120+
- ``True``: Draw line segments as straight lines in geographic coordinate
121+
systems.
122+
- ``"x"``: Draw line segments by first along *x*, then along *y*.
123+
- ``"y"``: Draw line segments by first along *y*, then along *x*.
124+
125+
Here, *x* and *y* have different meanings depending on the coordinate system:
126+
127+
- **Cartesian** coordinate system: *x* and *y* are the X- and Y-axes.
128+
- **Polar** coordinate system: *x* and *y* are theta and radius.
129+
- **Geographic** coordinate system: *x* and *y* are parallels and meridians.
130+
131+
**NOTE**: The ``straight_line`` parameter requires constant *z*-coordinates.
132+
133+
.. attention::
134+
135+
There exits a bug in GMT<=6.5.0 that, in geographic coordinate systems, the
136+
meaning of *x* and *y* is reversed, i.e., *x* means meridians and *y* means
137+
parallels. The bug is fixed by upstream
138+
`PR #8648 <https://github.com/GenericMappingTools/gmt/pull/8648>`__.
123139
{frame}
124140
{cmap}
125141
offset : str
@@ -189,6 +205,8 @@ def plot3d(
189205
``x``/``y``/``z``.
190206
{wrap}
191207
"""
208+
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
209+
# parameter.
192210
kwargs = self._preprocess(**kwargs)
193211

194212
kind = data_kind(data)

0 commit comments

Comments
 (0)