Skip to content

Commit

Permalink
Refactor Figure.plot and Figure.plot3d to avoid using the extra_array…
Browse files Browse the repository at this point in the history
…s parameter
  • Loading branch information
seisman committed Aug 4, 2024
1 parent 149c0be commit 4a4c8cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
18 changes: 8 additions & 10 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,26 @@ def plot( # noqa: PLR0912
kwargs = self._preprocess(**kwargs)

kind = data_kind(data)
extra_arrays = []
if kind == "none": # Add more columns for vectors input
if kind == "none": # Vectors input
data = {"x": x, "y": y}
# Parameters for vector styles
if (
kwargs.get("S") is not None
and kwargs["S"][0] in "vV"
and is_nonstr_iter(direction)
):
extra_arrays.extend(direction)
data.update({"x2": direction[0], "y2": direction[1]})
# Fill
if is_nonstr_iter(kwargs.get("G")):
extra_arrays.append(kwargs.get("G"))
data["fill"] = kwargs["G"]
del kwargs["G"]
# Size
if is_nonstr_iter(size):
extra_arrays.append(size)
data["size"] = size
# Intensity and transparency
for flag in ["I", "t"]:
for flag, name in ["I", "intensity"], ["t", "transparency"]:
if is_nonstr_iter(kwargs.get(flag)):
extra_arrays.append(kwargs.get(flag))
data[name] = kwargs[flag]
kwargs[flag] = ""
else:
for name, value in [
Expand All @@ -255,7 +255,5 @@ def plot( # noqa: PLR0912
pass

with Session() as lib:
with lib.virtualfile_in(
check_kind="vector", data=data, x=x, y=y, extra_arrays=extra_arrays
) as vintbl:
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
lib.call_module(module="plot", args=build_arg_list(kwargs, infile=vintbl))
23 changes: 8 additions & 15 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,26 @@ def plot3d( # noqa: PLR0912
kwargs = self._preprocess(**kwargs)

kind = data_kind(data)
extra_arrays = []

if kind == "none": # Add more columns for vectors input
if kind == "none": # Vectors input
data = {"x": x, "y": y, "z": z}
# Parameters for vector styles
if (
kwargs.get("S") is not None
and kwargs["S"][0] in "vV"
and is_nonstr_iter(direction)
):
extra_arrays.extend(direction)
data.update({"x2": direction[0], "y2": direction[1]})
# Fill
if is_nonstr_iter(kwargs.get("G")):
extra_arrays.append(kwargs.get("G"))
data["fill"] = kwargs["G"]
del kwargs["G"]
# Size
if is_nonstr_iter(size):
extra_arrays.append(size)
data["size"] = size
# Intensity and transparency
for flag in ["I", "t"]:
for flag, name in [("I", "intensity"), ("t", "transparency")]:
if is_nonstr_iter(kwargs.get(flag)):
extra_arrays.append(kwargs.get(flag))
data[name] = kwargs[flag]
kwargs[flag] = ""
else:
for name, value in [
Expand Down Expand Up @@ -232,12 +231,6 @@ def plot3d( # noqa: PLR0912

with Session() as lib:
with lib.virtualfile_in(
check_kind="vector",
data=data,
x=x,
y=y,
z=z,
extra_arrays=extra_arrays,
required_z=True,
check_kind="vector", data=data, required_z=True
) as vintbl:
lib.call_module(module="plot3d", args=build_arg_list(kwargs, infile=vintbl))

0 comments on commit 4a4c8cc

Please sign in to comment.