From 41a9e6a9a0bc7213b218e1ad95eef0279f0121ef Mon Sep 17 00:00:00 2001 From: core-man Date: Wed, 24 Mar 2021 17:51:07 +0800 Subject: [PATCH 01/11] Add test_plot_symbols.png into DVC --- pygmt/tests/baseline/test_plot_symbols.png.dvc | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pygmt/tests/baseline/test_plot_symbols.png.dvc diff --git a/pygmt/tests/baseline/test_plot_symbols.png.dvc b/pygmt/tests/baseline/test_plot_symbols.png.dvc new file mode 100644 index 00000000000..a45c7578347 --- /dev/null +++ b/pygmt/tests/baseline/test_plot_symbols.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 62a8c11527abb583a04797ff9407c364 + size: 23798 + path: test_plot_symbols.png From ebeabea3e344dbcee9637a94a52ed2ac6384ebc6 Mon Sep 17 00:00:00 2001 From: core-man Date: Wed, 24 Mar 2021 17:52:56 +0800 Subject: [PATCH 02/11] Allow passing an array as symbols for plot --- pygmt/src/plot.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index f3be49b598b..164e878df95 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -43,7 +43,9 @@ t="transparency", ) @kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") -def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs): +def plot( + self, x=None, y=None, data=None, sizes=None, direction=None, symbol=None, **kwargs +): r""" Plot lines, polygons, and symbols in 2-D. @@ -86,6 +88,8 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs): should be a list of two 1d arrays with the vector directions. These can be angle and length, azimuth and length, or x and y components, depending on the style options chosen. + symbol : 1d array + The symbols of the data points. Only valid if using ``x``/``y``. {J} {R} straight_line : bool or str @@ -206,8 +210,10 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs): kind = data_kind(data, x, y) extra_arrays = [] - if "S" in kwargs and kwargs["S"][0] in "vV" and direction is not None: - extra_arrays.extend(direction) + if "S" in kwargs and len(kwargs["S"]) > 0: + if kwargs["S"][0] in "vV" and direction is not None: + extra_arrays.extend(direction) + if "G" in kwargs and not isinstance(kwargs["G"], str): if kind != "vectors": raise GMTInvalidInput( @@ -215,6 +221,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs): ) extra_arrays.append(kwargs["G"]) del kwargs["G"] + if sizes is not None: if kind != "vectors": raise GMTInvalidInput( @@ -231,6 +238,13 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs): extra_arrays.append(kwargs[flag]) kwargs[flag] = "" + if symbol is not None: + if kind != "vectors": + raise GMTInvalidInput( + "Can't use arrays for symbol if data is matrix or file." + ) + extra_arrays.append(symbol) + with Session() as lib: # Choose how data will be passed in to the module file_context = lib.virtualfile_from_data( From c92287003e9c291fad626b84d519fa56b56ebd01 Mon Sep 17 00:00:00 2001 From: core-man Date: Wed, 24 Mar 2021 17:53:15 +0800 Subject: [PATCH 03/11] Add tests for 1d-array symbols for plot --- pygmt/tests/test_plot.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index a57692b76c0..e40af7441e1 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -93,19 +93,23 @@ def test_plot_fail_no_data(data): ) -def test_plot_fail_color_size_intensity(data): +def test_plot_fail_1d_array_using_data(data): """ - Should raise an exception if array color, sizes and intensity are used with - matrix. + Should raise an exception if array color, sizes, intensity and symbol are + used with matrix. """ fig = Figure() kwargs = dict(data=data, region=region, projection="X10c", frame="afg") with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", color=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): - fig.plot(style="cc", sizes=data[:, 2], color="red", **kwargs) + fig.plot(style="cc", color="red", sizes=data[:, 2], **kwargs) with pytest.raises(GMTInvalidInput): fig.plot(style="c0.2c", color="red", intensity=data[:, 2], **kwargs) + with pytest.raises(GMTInvalidInput): + fig.plot( + style="0.2c", color="red", symbol=np.full(len(data[:, 2]), "c"), **kwargs + ) @check_figures_equal() @@ -347,6 +351,25 @@ def test_plot_sizes_colors_transparencies(): return fig_ref, fig_test +@pytest.mark.mpl_image_compare +def test_plot_symbols(data, region): + """ + Plot the data using array-like symbols. + """ + fig = Figure() + fig.plot( + x=data[:, 0], + y=data[:, 1], + region=region, + projection="X4i", + style="0.5c", + color="blue", + symbol=np.full(len(data[:, 0]), "c"), + frame="af", + ) + return fig + + @pytest.mark.mpl_image_compare def test_plot_matrix(data): """ From 1c48b390024336ffacf07e66b76992d57cd490be Mon Sep 17 00:00:00 2001 From: core-man Date: Tue, 13 Apr 2021 15:24:42 +0800 Subject: [PATCH 04/11] Automactically set style to True if symbol is used --- pygmt/src/plot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 164e878df95..1e9ed9d1e82 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -210,7 +210,7 @@ def plot( kind = data_kind(data, x, y) extra_arrays = [] - if "S" in kwargs and len(kwargs["S"]) > 0: + if "S" in kwargs and isinstance(kwargs["S"], str): if kwargs["S"][0] in "vV" and direction is not None: extra_arrays.extend(direction) @@ -239,6 +239,9 @@ def plot( kwargs[flag] = "" if symbol is not None: + if "S" not in kwargs: + kwargs["S"] = True + if kind != "vectors": raise GMTInvalidInput( "Can't use arrays for symbol if data is matrix or file." From 199f861872d0d3971746933d635ddb0d74f91e0c Mon Sep 17 00:00:00 2001 From: core-man Date: Tue, 13 Apr 2021 15:25:58 +0800 Subject: [PATCH 05/11] Update test_plot_symbols.png --- pygmt/tests/baseline/test_plot_symbols.png.dvc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/baseline/test_plot_symbols.png.dvc b/pygmt/tests/baseline/test_plot_symbols.png.dvc index a45c7578347..2b0885b75f6 100644 --- a/pygmt/tests/baseline/test_plot_symbols.png.dvc +++ b/pygmt/tests/baseline/test_plot_symbols.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 62a8c11527abb583a04797ff9407c364 - size: 23798 +- md5: 394a4e806a99234f239437252a99254c + size: 13759 path: test_plot_symbols.png From 3d97972d6805e3522f42d4e6596cdcdc01ab40cc Mon Sep 17 00:00:00 2001 From: core-man Date: Tue, 13 Apr 2021 15:26:43 +0800 Subject: [PATCH 06/11] Update test_plot_symbols --- pygmt/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index 67c2469fa6f..4de6d1e40f6 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -309,9 +309,9 @@ def test_plot_symbols(data, region): x=data[:, 0], y=data[:, 1], region=region, - projection="X4i", - style="0.5c", + projection="X4c", color="blue", + sizes=np.full(len(data[:, 0]), 0.5), symbol=np.full(len(data[:, 0]), "c"), frame="af", ) From ab2a9da043f61bbc1e0d085958a75ec13519db57 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 26 Sep 2024 21:48:29 +0800 Subject: [PATCH 07/11] Fix comment in tests --- pygmt/tests/test_plot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index f9f7e945a38..763f003e44f 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -91,10 +91,10 @@ def test_plot_fail_no_data(data, region): ) -def test_plot_fail_1d_array_using_data(data, region): +def test_plot_fail_1d_array_with_data(data, region): """ - Should raise an exception if array color, sizes, intensity and symbol are - used with matrix. + Should raise an exception if arrays of fill, size, intensity, transparency and + symbol are specified when data is given. """ fig = Figure() kwargs = {"data": data, "region": region, "projection": "X10c", "frame": "afg"} From 17f7cc784815ee19ce726088f2c53fdd083ca64b Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 26 Sep 2024 21:49:06 +0800 Subject: [PATCH 08/11] Add one more comment --- pygmt/src/plot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 56ff5381cd9..74cce5a4fb2 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -232,6 +232,7 @@ def plot( # noqa: PLR0912 if is_nonstr_iter(kwargs.get(flag)): extra_arrays.append(kwargs.get(flag)) kwargs[flag] = "" + # Symbol must be at the last column if is_nonstr_iter(symbol): if "S" not in kwargs: kwargs["S"] = True From 02ebc94874f550002c08f28254e6fabca2f69e46 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 26 Sep 2024 22:01:43 +0800 Subject: [PATCH 09/11] Add a new baseline image --- pygmt/tests/baseline/test_plot_symbol.png.dvc | 5 +++++ pygmt/tests/baseline/test_plot_symbols.png.dvc | 4 ---- pygmt/tests/test_plot.py | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 pygmt/tests/baseline/test_plot_symbol.png.dvc delete mode 100644 pygmt/tests/baseline/test_plot_symbols.png.dvc diff --git a/pygmt/tests/baseline/test_plot_symbol.png.dvc b/pygmt/tests/baseline/test_plot_symbol.png.dvc new file mode 100644 index 00000000000..22184413c7f --- /dev/null +++ b/pygmt/tests/baseline/test_plot_symbol.png.dvc @@ -0,0 +1,5 @@ +outs: +- md5: bf71e5e72529a85d9ac45aa71321962e + size: 3798 + hash: md5 + path: test_plot_symbol.png diff --git a/pygmt/tests/baseline/test_plot_symbols.png.dvc b/pygmt/tests/baseline/test_plot_symbols.png.dvc deleted file mode 100644 index 2b0885b75f6..00000000000 --- a/pygmt/tests/baseline/test_plot_symbols.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 394a4e806a99234f239437252a99254c - size: 13759 - path: test_plot_symbols.png diff --git a/pygmt/tests/test_plot.py b/pygmt/tests/test_plot.py index 763f003e44f..48608cf51ce 100644 --- a/pygmt/tests/test_plot.py +++ b/pygmt/tests/test_plot.py @@ -300,19 +300,19 @@ def test_plot_sizes_colors_transparencies(): @pytest.mark.mpl_image_compare -def test_plot_symbols(data, region): +def test_plot_symbol(): """ Plot the data using array-like symbols. """ fig = Figure() fig.plot( - x=data[:, 0], - y=data[:, 1], - region=region, + x=[1, 2, 3, 4], + y=[1, 1, 1, 1], + region=[0, 5, 0, 5], projection="X4c", fill="blue", - size=[0.5] * data.shape[0], - symbol=["c"] * data.shape[0], + size=[0.1, 0.2, 0.3, 0.4], + symbol=["c", "t", "i", "s"], frame="af", ) return fig From ecd039545f14e6f716553817a304e4f4dbda8b72 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 27 Sep 2024 12:45:36 +0800 Subject: [PATCH 10/11] Fix the order --- pygmt/src/plot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 74cce5a4fb2..8397fe630ee 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -51,7 +51,7 @@ ) @kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") def plot( # noqa: PLR0912 - self, data=None, x=None, y=None, size=None, direction=None, symbol=None, **kwargs + self, data=None, x=None, y=None, size=None, symbol=None, direction=None, **kwargs ): r""" Plot lines, polygons, and symbols in 2-D. @@ -91,13 +91,13 @@ def plot( # noqa: PLR0912 size : 1-D array The size of the data points in units specified using ``style``. Only valid if using ``x``/``y``. + symbol : 1-D array + The symbols of the data points. Only valid if using ``x``/``y``. direction : list of two 1-D arrays If plotting vectors (using ``style="V"`` or ``style="v"``), then should be a list of two 1-D arrays with the vector directions. These can be angle and length, azimuth and length, or x and y components, depending on the style options chosen. - symbol : 1-D array - The symbols of the data points. Only valid if using ``x``/``y``. {projection} {region} straight_line : bool or str From 45cf1275eaefd1f8f26c17694d2db64d9505e776 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 24 Oct 2024 00:39:29 +0800 Subject: [PATCH 11/11] Fix styling --- pygmt/src/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 2dc5ed14707..1cad190c8ee 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -48,7 +48,7 @@ w="wrap", ) @kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") -def plot( # noqa: PLR0912 +def plot( self, data=None, x=None, y=None, size=None, symbol=None, direction=None, **kwargs ): r"""