Skip to content

Commit f37802f

Browse files
committed
Initial design of Figure.scatter
1 parent b6f3e2b commit f37802f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

pygmt/figure.py

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ def _repr_html_(self):
418418
plot3d,
419419
psconvert,
420420
rose,
421+
scatter,
421422
set_panel,
422423
shift_origin,
423424
solar,

pygmt/src/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from pygmt.src.project import project
4343
from pygmt.src.psconvert import psconvert
4444
from pygmt.src.rose import rose
45+
from pygmt.src.scatter import scatter
4546
from pygmt.src.select import select
4647
from pygmt.src.shift_origin import shift_origin
4748
from pygmt.src.solar import solar

pygmt/src/scatter.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
scatter - Scatter plot.
3+
"""
4+
5+
from pygmt.helpers import is_nonstr_iter
6+
7+
8+
def _parse_symbol_size(symbol, size):
9+
"""
10+
Parse the symbol and size into a style string.
11+
12+
>>> _parse_symbol_size("c", 0.2)
13+
'c0.2'
14+
>>> _parse_symbol_size("c", "0.2c")
15+
'c0.2c'
16+
>>> _parse_symbol_size("c", [0.2, 0.3])
17+
'c'
18+
>>> _parse_symbol_size(["c", "t"], "0.2c"])
19+
'0.2c'
20+
>>> _parse_symbol_size(["c", "t"], [0.2, 0.3])
21+
''
22+
"""
23+
return "".join(f"{arg}" for arg in [symbol, size] if not is_nonstr_iter(arg))
24+
25+
26+
def scatter(self, x, y, symbol, size, **kwargs):
27+
"""
28+
Plot scatter points on a map.
29+
30+
Parameters
31+
----------
32+
x, y : array-like
33+
The coordinates of the points to plot.
34+
symbol : str or sequence
35+
The symbol to use for the points.
36+
size : float or sequence
37+
The size of the points.
38+
"""
39+
kwargs = self._preprocess(**kwargs)
40+
41+
# style is a combination of symbol and size, but only if they are string-like
42+
style = _parse_symbol_size(symbol, size)
43+
if not is_nonstr_iter(symbol):
44+
symbol = None
45+
if not is_nonstr_iter(size):
46+
size = None
47+
48+
self.plot(x=x, y=y, style=style, symbol=symbol, size=size, **kwargs)

0 commit comments

Comments
 (0)