Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.plot/Figure.plot3d: Improve the docstrings for straight_line #3720

Merged
merged 12 commits into from
Jan 6, 2025
49 changes: 36 additions & 13 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
plot - Plot in two dimensions.
"""

from typing import Literal

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
Expand Down Expand Up @@ -49,7 +51,15 @@
)
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
def plot(
self, data=None, x=None, y=None, size=None, symbol=None, direction=None, **kwargs
self,
data=None,
x=None,
y=None,
size=None,
symbol=None,
direction=None,
straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001
**kwargs,
):
r"""
Plot lines, polygons, and symbols in 2-D.
Expand Down Expand Up @@ -98,18 +108,29 @@ def plot(
depending on the style options chosen.
{projection}
{region}
straight_line : 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
``straight_line=True``.
Alternatively, add **m** to draw the line by first following a
meridian, then a parallel. Or append **p** to start following a
parallel, then a meridian. (This can be practical to draw a line
along parallels, for example). For Cartesian data, points are
simply connected, unless you append **x** or **y** to draw
stair-case curves that whose first move is along *x* or *y*,
respectively.
straight_line
By default, line segments are drawn as straight lines in the Cartesian and polar
coordinate systems, and as great circle arcs (by resampling coarse input data
along such arcs) in the geographic coordinate system. The ``straight_line``
parameter can control the drawing of line segments. Valid values are:

- ``True``: Draw line segments as straight lines in geographic coordinate
systems.
- ``"x"``: Draw line segments by first along *x*, then along *y*.
- ``"y"``: Draw line segments by first along *y*, then along *x*.

Here, *x* and *y* have different meanings depending on the coordinate system:

- **Cartesian** coordinate system: *x* and *y* are the X- and Y-axes.
- **Polar** coordinate system: *x* and *y* are theta and radius.
- **Geographic** coordinate system: *x* and *y* are parallels and meridians.

.. attention::

There exits a bug in GMT<=6.5.0 that, in geographic coordinate systems, the
meaning of *x* and *y* is reversed, i.e., *x* means meridians and *y* means
parallels. The bug is fixed by upstream
`PR #8648 <https://github.com/GenericMappingTools/gmt/pull/8648>`__.
{frame}
{cmap}
offset : str
Expand Down Expand Up @@ -206,6 +227,8 @@ def plot(
``x``/``y``.
{wrap}
"""
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
# parameter.
kwargs = self._preprocess(**kwargs)

kind = data_kind(data)
Expand Down
42 changes: 30 additions & 12 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
plot3d - Plot in three dimensions.
"""

from typing import Literal

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
Expand Down Expand Up @@ -58,6 +60,7 @@ def plot3d(
size=None,
symbol=None,
direction=None,
straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001
**kwargs,
):
r"""
Expand Down Expand Up @@ -108,18 +111,31 @@ def plot3d(
zscale/zsize : float or str
Set z-axis scaling or z-axis size.
{region}
straight_line : 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 ``straight_line``.
Alternatively, add **m** to draw the line by first following a
meridian, then a parallel. Or append **p** to start following a
parallel, then a meridian. (This can be practical to draw a line
along parallels, for example). For Cartesian data, points are
simply connected, unless you append **x** or **y** to draw
stair-case curves that whose first move is along *x* or *y*,
respectively. **Note**: The ``straight_line`` parameter requires
constant *z*-coordinates.
straight_line
By default, line segments are drawn as straight lines in the Cartesian and polar
coordinate systems, and as great circle arcs (by resampling coarse input data
along such arcs) in the geographic coordinate system. The ``straight_line``
parameter can control the drawing of line segments. Valid values are:

- ``True``: Draw line segments as straight lines in geographic coordinate
systems.
- ``"x"``: Draw line segments by first along *x*, then along *y*.
- ``"y"``: Draw line segments by first along *y*, then along *x*.

Here, *x* and *y* have different meanings depending on the coordinate system:

- **Cartesian** coordinate system: *x* and *y* are the X- and Y-axes.
- **Polar** coordinate system: *x* and *y* are theta and radius.
- **Geographic** coordinate system: *x* and *y* are parallels and meridians.

**NOTE**: The ``straight_line`` parameter requires constant *z*-coordinates.

.. attention::

There exits a bug in GMT<=6.5.0 that, in geographic coordinate systems, the
meaning of *x* and *y* is reversed, i.e., *x* means meridians and *y* means
parallels. The bug is fixed by upstream
`PR #8648 <https://github.com/GenericMappingTools/gmt/pull/8648>`__.
{frame}
{cmap}
offset : str
Expand Down Expand Up @@ -189,6 +205,8 @@ def plot3d(
``x``/``y``/``z``.
{wrap}
"""
# TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line"
# parameter.
kwargs = self._preprocess(**kwargs)

kind = data_kind(data)
Expand Down
Loading