Skip to content

Commit

Permalink
Initial design of Figure.scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Nov 8, 2024
1 parent b6f3e2b commit f37802f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def _repr_html_(self):
plot3d,
psconvert,
rose,
scatter,
set_panel,
shift_origin,
solar,
Expand Down
1 change: 1 addition & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pygmt.src.project import project
from pygmt.src.psconvert import psconvert
from pygmt.src.rose import rose
from pygmt.src.scatter import scatter
from pygmt.src.select import select
from pygmt.src.shift_origin import shift_origin
from pygmt.src.solar import solar
Expand Down
48 changes: 48 additions & 0 deletions pygmt/src/scatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
scatter - Scatter plot.
"""

from pygmt.helpers import is_nonstr_iter


def _parse_symbol_size(symbol, size):
"""
Parse the symbol and size into a style string.
>>> _parse_symbol_size("c", 0.2)
'c0.2'
>>> _parse_symbol_size("c", "0.2c")
'c0.2c'
>>> _parse_symbol_size("c", [0.2, 0.3])
'c'
>>> _parse_symbol_size(["c", "t"], "0.2c"])
'0.2c'
>>> _parse_symbol_size(["c", "t"], [0.2, 0.3])
''
"""
return "".join(f"{arg}" for arg in [symbol, size] if not is_nonstr_iter(arg))


def scatter(self, x, y, symbol, size, **kwargs):
"""
Plot scatter points on a map.
Parameters
----------
x, y : array-like
The coordinates of the points to plot.
symbol : str or sequence
The symbol to use for the points.
size : float or sequence
The size of the points.
"""
kwargs = self._preprocess(**kwargs)

Check warning on line 39 in pygmt/src/scatter.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/scatter.py#L39

Added line #L39 was not covered by tests

# style is a combination of symbol and size, but only if they are string-like
style = _parse_symbol_size(symbol, size)
if not is_nonstr_iter(symbol):
symbol = None
if not is_nonstr_iter(size):
size = None

Check warning on line 46 in pygmt/src/scatter.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/scatter.py#L42-L46

Added lines #L42 - L46 were not covered by tests

self.plot(x=x, y=y, style=style, symbol=symbol, size=size, **kwargs)

Check warning on line 48 in pygmt/src/scatter.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/scatter.py#L48

Added line #L48 was not covered by tests

0 comments on commit f37802f

Please sign in to comment.