Skip to content

Commit ce89ccb

Browse files
authored
Figure.plot3d: Add the "symbol" parameter to support plotting data points with varying symbols (#3559)
1 parent b2dcd88 commit ce89ccb

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

pygmt/src/plot3d.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@
5050
)
5151
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence")
5252
def plot3d(
53-
self, data=None, x=None, y=None, z=None, size=None, direction=None, **kwargs
53+
self,
54+
data=None,
55+
x=None,
56+
y=None,
57+
z=None,
58+
size=None,
59+
symbol=None,
60+
direction=None,
61+
**kwargs,
5462
):
5563
r"""
5664
Plot lines, polygons, and symbols in 3-D.
@@ -89,6 +97,8 @@ def plot3d(
8997
size : 1-D array
9098
The size of the data points in units specified in ``style``.
9199
Only valid if using ``x``/``y``/``z``.
100+
symbol : 1-D array
101+
The symbols of the data points. Only valid if using ``x``/``y``.
92102
direction : list of two 1-D arrays
93103
If plotting vectors (using ``style="V"`` or ``style="v"``), then
94104
should be a list of two 1-D arrays with the vector directions. These
@@ -204,13 +214,19 @@ def plot3d(
204214
if is_nonstr_iter(kwargs.get(flag)):
205215
extra_arrays.append(kwargs.get(flag))
206216
kwargs[flag] = ""
217+
# Symbol must be at the last column
218+
if is_nonstr_iter(symbol):
219+
if "S" not in kwargs:
220+
kwargs["S"] = True
221+
extra_arrays.append(symbol)
207222
else:
208223
for name, value in [
209224
("direction", direction),
210225
("fill", kwargs.get("G")),
211226
("size", size),
212227
("intensity", kwargs.get("I")),
213228
("transparency", kwargs.get("t")),
229+
("symbol", symbol),
214230
]:
215231
if is_nonstr_iter(value):
216232
raise GMTInvalidInput(f"'{name}' can't be 1-D array if 'data' is used.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
outs:
2+
- md5: 5593426a0fde7cc591e89b8309f73402
3+
size: 9170
4+
hash: md5
5+
path: test_plot3d_symbol.png

pygmt/tests/test_plot3d.py

+22
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,28 @@ def test_plot3d_sizes_colors_transparencies():
315315
return fig
316316

317317

318+
@pytest.mark.mpl_image_compare
319+
def test_plot3d_symbol():
320+
"""
321+
Plot the data using array-like symbols.
322+
"""
323+
fig = Figure()
324+
fig.plot3d(
325+
x=[1, 2, 3, 4],
326+
y=[1, 2, 3, 4],
327+
z=[1, 2, 3, 4],
328+
region=[0, 5, 0, 5, 0, 5],
329+
projection="X4c",
330+
zsize="3c",
331+
fill="blue",
332+
size=[0.1, 0.2, 0.3, 0.4],
333+
symbol=["c", "t", "i", "u"],
334+
frame=["WSenZ", "afg"],
335+
perspective=[135, 30],
336+
)
337+
return fig
338+
339+
318340
@pytest.mark.mpl_image_compare
319341
@pytest.mark.mpl_image_compare(filename="test_plot3d_matrix.png")
320342
@pytest.mark.parametrize("fill", ["#aaaaaa", 170])

0 commit comments

Comments
 (0)