From 4391db2ba9945051009329b8e992cc0451ee0f0c Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 24 Jul 2024 15:06:49 +0800 Subject: [PATCH] Refactor Figure.plot and Figure.plot3d to avoid using the extra_arrays parameter --- pygmt/src/plot.py | 18 ++++++++---------- pygmt/src/plot3d.py | 23 ++++++++--------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index f313c37822b..76d0314c609 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -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 [ @@ -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)) diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index 704a44a4f7f..c0285a4c7cb 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -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 [ @@ -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))