Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot square or cube by default for geopandas Point/MultiPoint types #1405

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56f5c54
adding if statement for geopandas default behavior.
yohaimagen Aug 2, 2021
ef2e89a
format corections
yohaimagen Aug 2, 2021
af36475
chcking that data is an object to be sure it has __dict__ (make sure …
yohaimagen Aug 2, 2021
e1543e8
Update pygmt/src/plot.py
yohaimagen Aug 2, 2021
d60ee1b
not checking if data is not None allrady been verefide in data_kind f…
yohaimagen Aug 2, 2021
4bd2d5e
reformat style
yohaimagen Aug 3, 2021
93c5312
Update pygmt/src/plot.py
yohaimagen Aug 3, 2021
5daeb42
Update pygmt/src/plot.py
yohaimagen Aug 3, 2021
2041146
adding the if statment to plot3d.py
yohaimagen Aug 3, 2021
9f69437
changing the style to s-.2c and u0.2c for plot and plot3d respectivly
yohaimagen Aug 3, 2021
6409d34
testing defualt behavior of plot and plot3d with geopandas Point and …
yohaimagen Aug 4, 2021
7a60c4f
style reformat
yohaimagen Aug 4, 2021
dd1c9b8
style reformat imports
yohaimagen Aug 4, 2021
1979249
add comments to new tests
yohaimagen Aug 4, 2021
966c9e5
reformat imports
yohaimagen Aug 5, 2021
35e66d1
Update pygmt/tests/test_geopandas.py
yohaimagen Aug 6, 2021
1590a26
Update pygmt/tests/test_geopandas.py
yohaimagen Aug 6, 2021
b2204ad
change the test figuers size to make smaller sizewd figuers
yohaimagen Aug 6, 2021
702b038
Merge branch 'main' into geopandas-point-default-style
michaelgrund Aug 8, 2021
0b642a9
adding test for non defualt style
yohaimagen Aug 11, 2021
5d778f1
adding a coment explaining the if statment
yohaimagen Aug 12, 2021
e36b3eb
reformat
yohaimagen Aug 12, 2021
96b683c
Update pygmt/src/plot.py
yohaimagen Aug 14, 2021
e57ec91
Update pygmt/src/plot3d.py
yohaimagen Aug 14, 2021
d9a02a7
Merge branch 'main' into geopandas-point-default-style
seisman Aug 14, 2021
4d13394
Update pygmt/tests/test_geopandas.py
yohaimagen Aug 17, 2021
b7827e0
Update pygmt/tests/test_geopandas.py
yohaimagen Aug 17, 2021
d62608c
reformat
yohaimagen Aug 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
seisman marked this conversation as resolved.
Show resolved Hide resolved
"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"
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
if "G" in kwargs and not isinstance(kwargs["G"], str):
if kind != "vectors":
raise GMTInvalidInput(
Expand Down
6 changes: 6 additions & 0 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
"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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 48e8bd30372aa5ab9004c1fd53db7ab6
size: 12132
path: test_geopandas_plot3d_default_cube.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 54cdcd316554c9db4d71cc2bea2a690a
size: 12028
path: test_geopandas_plot3d_non_default_circle.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 6c395fb503f67d024925a2c86cae7ba8
size: 4272
path: test_geopandas_plot_default_square.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 4a946506f8a48be04792fdabffc6fa07
size: 4451
path: test_geopandas_plot_non_default_circle.png
69 changes: 68 additions & 1 deletion pygmt/tests/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 geopandas DataFrame with Point
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
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 geopandas DataFrame with MultiPoint
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
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