diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 520df6773df..31db1e25771 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -207,6 +207,12 @@ def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs): extra_arrays = [] if "S" in kwargs and kwargs["S"][0] in "vV" and direction is not None: extra_arrays.extend(direction) + elif ( + "S" not in kwargs + and kind == "geojson" + and data.geom_type.isin(["Point", "MultiPoint"]).all() + ): # checking if the geometry of a geoDataFrame is Point or MultiPoint + kwargs["S"] = "s0.2c" if "G" in kwargs and not isinstance(kwargs["G"], str): if kind != "vectors": raise GMTInvalidInput( diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index d1e4a327647..84f229cdc92 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -177,6 +177,12 @@ def plot3d( extra_arrays = [] if "S" in kwargs and kwargs["S"][0] in "vV" and direction is not None: extra_arrays.extend(direction) + elif ( + "S" not in kwargs + and kind == "geojson" + and data.geom_type.isin(["Point", "MultiPoint"]).all() + ): # checking if the geometry of a geoDataFrame is Point or MultiPoint + kwargs["S"] = "u0.2c" if "G" in kwargs and not isinstance(kwargs["G"], str): if kind != "vectors": raise GMTInvalidInput( diff --git a/pygmt/tests/baseline/test_geopandas_plot3d_default_cube.png.dvc b/pygmt/tests/baseline/test_geopandas_plot3d_default_cube.png.dvc new file mode 100644 index 00000000000..9493b9b9ca1 --- /dev/null +++ b/pygmt/tests/baseline/test_geopandas_plot3d_default_cube.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 48e8bd30372aa5ab9004c1fd53db7ab6 + size: 12132 + path: test_geopandas_plot3d_default_cube.png diff --git a/pygmt/tests/baseline/test_geopandas_plot3d_non_default_circle.png.dvc b/pygmt/tests/baseline/test_geopandas_plot3d_non_default_circle.png.dvc new file mode 100644 index 00000000000..58d7a3ba4fe --- /dev/null +++ b/pygmt/tests/baseline/test_geopandas_plot3d_non_default_circle.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 54cdcd316554c9db4d71cc2bea2a690a + size: 12028 + path: test_geopandas_plot3d_non_default_circle.png diff --git a/pygmt/tests/baseline/test_geopandas_plot_default_square.png.dvc b/pygmt/tests/baseline/test_geopandas_plot_default_square.png.dvc new file mode 100644 index 00000000000..c52a04a4696 --- /dev/null +++ b/pygmt/tests/baseline/test_geopandas_plot_default_square.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 6c395fb503f67d024925a2c86cae7ba8 + size: 4272 + path: test_geopandas_plot_default_square.png diff --git a/pygmt/tests/baseline/test_geopandas_plot_non_default_circle.png.dvc b/pygmt/tests/baseline/test_geopandas_plot_non_default_circle.png.dvc new file mode 100644 index 00000000000..d7316004d2a --- /dev/null +++ b/pygmt/tests/baseline/test_geopandas_plot_non_default_circle.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 4a946506f8a48be04792fdabffc6fa07 + size: 4451 + path: test_geopandas_plot_non_default_circle.png diff --git a/pygmt/tests/test_geopandas.py b/pygmt/tests/test_geopandas.py index d7f04e6cb45..575670cf123 100644 --- a/pygmt/tests/test_geopandas.py +++ b/pygmt/tests/test_geopandas.py @@ -3,7 +3,7 @@ """ import numpy.testing as npt import pytest -from pygmt import info +from pygmt import Figure, info gpd = pytest.importorskip("geopandas") shapely = pytest.importorskip("shapely") @@ -64,3 +64,70 @@ def test_geopandas_info_shapely(gdf, geomtype, desired): geom = gdf.loc[geomtype].geometry output = info(table=geom, per_column=True) npt.assert_allclose(actual=output, desired=desired) + + +@pytest.mark.mpl_image_compare +def test_geopandas_plot_default_square(): + """ + Check the default behavior of plotting a geopandas DataFrame with Point + geometry in 2d. + """ + point = shapely.geometry.Point(1, 2) + gdf = gpd.GeoDataFrame(geometry=[point]) + fig = Figure() + fig.plot(data=gdf, region=[0, 2, 1, 3], projection="X2c", frame=True) + return fig + + +@pytest.mark.mpl_image_compare +def test_geopandas_plot3d_default_cube(): + """ + Check the default behavior of plotting a geopandas DataFrame with + MultiPoint geometry in 3d. + """ + multipoint = shapely.geometry.MultiPoint([(0.5, 0.5, 0.5), (1.5, 1.5, 1.5)]) + gdf = gpd.GeoDataFrame(geometry=[multipoint]) + fig = Figure() + fig.plot3d( + data=gdf, + perspective=[315, 25], + region=[0, 2, 0, 2, 0, 2], + projection="X2c", + frame=["WsNeZ1", "xag", "yag", "zag"], + zscale=1.5, + ) + return fig + + +@pytest.mark.mpl_image_compare +def test_geopandas_plot_non_default_circle(): + """ + Check the default behavior of plotting geopandas DataFrame with Point + geometry in 2d. + """ + point = shapely.geometry.Point(1, 2) + gdf = gpd.GeoDataFrame(geometry=[point]) + fig = Figure() + fig.plot(data=gdf, region=[0, 2, 1, 3], projection="X2c", frame=True, style="c0.2c") + return fig + + +@pytest.mark.mpl_image_compare +def test_geopandas_plot3d_non_default_circle(): + """ + Check the default behavior of plotting geopandas DataFrame with MultiPoint + geometry in 3d. + """ + multipoint = shapely.geometry.MultiPoint([(0.5, 0.5, 0.5), (1.5, 1.5, 1.5)]) + gdf = gpd.GeoDataFrame(geometry=[multipoint]) + fig = Figure() + fig.plot3d( + data=gdf, + perspective=[315, 25], + region=[0, 2, 0, 2, 0, 2], + projection="X2c", + frame=["WsNeZ1", "xag", "yag", "zag"], + zscale=1.5, + style="c0.2c", + ) + return fig