Skip to content

Commit f1e6aca

Browse files
committed
Refactor Figure.plot and Figure.plot3d to avoid using the extra_arrays parameter
1 parent b7d2635 commit f1e6aca

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

pygmt/src/plot.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,26 @@ def plot( # noqa: PLR0912
209209
kwargs = self._preprocess(**kwargs)
210210

211211
kind = data_kind(data)
212-
extra_arrays = []
213-
if kind == "none": # Add more columns for vectors input
212+
if kind == "none": # Vectors input
213+
data = {"x": x, "y": y}
214214
# Parameters for vector styles
215215
if (
216216
kwargs.get("S") is not None
217217
and kwargs["S"][0] in "vV"
218218
and is_nonstr_iter(direction)
219219
):
220-
extra_arrays.extend(direction)
220+
data.update({"x2": direction[0], "y2": direction[1]})
221221
# Fill
222222
if is_nonstr_iter(kwargs.get("G")):
223-
extra_arrays.append(kwargs.get("G"))
223+
data["fill"] = kwargs["G"]
224224
del kwargs["G"]
225225
# Size
226226
if is_nonstr_iter(size):
227-
extra_arrays.append(size)
227+
data["size"] = size
228228
# Intensity and transparency
229-
for flag in ["I", "t"]:
229+
for flag, name in ["I", "intensity"], ["t", "transparency"]:
230230
if is_nonstr_iter(kwargs.get(flag)):
231-
extra_arrays.append(kwargs.get(flag))
231+
data[name] = kwargs[flag]
232232
kwargs[flag] = ""
233233
else:
234234
for name, value in [
@@ -255,7 +255,5 @@ def plot( # noqa: PLR0912
255255
pass
256256

257257
with Session() as lib:
258-
with lib.virtualfile_in(
259-
check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays
260-
) as vintbl:
258+
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
261259
lib.call_module(module="plot", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/plot3d.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,26 @@ def plot3d( # noqa: PLR0912
184184
kwargs = self._preprocess(**kwargs)
185185

186186
kind = data_kind(data)
187-
extra_arrays = []
188-
189-
if kind == "none": # Add more columns for vectors input
187+
if kind == "none": # Vectors input
188+
data = {"x": x, "y": y, "z": z}
190189
# Parameters for vector styles
191190
if (
192191
kwargs.get("S") is not None
193192
and kwargs["S"][0] in "vV"
194193
and is_nonstr_iter(direction)
195194
):
196-
extra_arrays.extend(direction)
195+
data.update({"x2": direction[0], "y2": direction[1]})
197196
# Fill
198197
if is_nonstr_iter(kwargs.get("G")):
199-
extra_arrays.append(kwargs.get("G"))
198+
data["fill"] = kwargs["G"]
200199
del kwargs["G"]
201200
# Size
202201
if is_nonstr_iter(size):
203-
extra_arrays.append(size)
202+
data["size"] = size
204203
# Intensity and transparency
205-
for flag in ["I", "t"]:
204+
for flag, name in [("I", "intensity"), ("t", "transparency")]:
206205
if is_nonstr_iter(kwargs.get(flag)):
207-
extra_arrays.append(kwargs.get(flag))
206+
data[name] = kwargs[flag]
208207
kwargs[flag] = ""
209208
else:
210209
for name, value in [
@@ -232,12 +231,6 @@ def plot3d( # noqa: PLR0912
232231

233232
with Session() as lib:
234233
with lib.virtualfile_in(
235-
check_kind="vector",
236-
data=data,
237-
x=x,
238-
y=y,
239-
z=z,
240-
extra_arrays=extra_arrays,
241-
required_z=True,
234+
check_kind="vector", data=data, required_z=True
242235
) as vintbl:
243236
lib.call_module(module="plot3d", args=build_arg_list(kwargs, infile=vintbl))

0 commit comments

Comments
 (0)