Skip to content

Commit 32cc7a2

Browse files
michaelgrundseismanactions-botyvonnefroehlich
authored
Update the gallery example for plotting lines with LineString/MultiLineString geometry (#3711)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: actions-bot <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 3134188 commit 32cc7a2

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

examples/gallery/lines/linestrings.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
GeoPandas: Plotting lines with LineString or MultiLineString geometry
3+
=====================================================================
4+
5+
The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as lines
6+
with LineString or MultiLineString geometry types stored in a
7+
:class:`geopandas.GeoDataFrame` object or any object that implements the
8+
`__geo_interface__ <https://gist.github.com/sgillies/2217756>`__ property.
9+
10+
Use :func:`geopandas.read_file` to load data from any supported OGR format such as a
11+
shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. Then, pass the
12+
:class:`geopandas.GeoDataFrame` object as an argument to the ``data`` parameter of
13+
:meth:`pygmt.Figure.plot`, and style the lines using the ``pen`` parameter.
14+
"""
15+
16+
# %%
17+
import geodatasets
18+
import geopandas as gpd
19+
import pygmt
20+
21+
# Read a sample dataset provided by the geodatasets package.
22+
# The dataset contains large rivers in Europe, stored as LineString/MultiLineString
23+
# geometry types.
24+
gdf = gpd.read_file(geodatasets.get_path("eea large_rivers"))
25+
26+
# Convert object to EPSG 4326 coordinate system
27+
gdf = gdf.to_crs("EPSG:4326")
28+
print(gdf.head())
29+
30+
# %%
31+
fig = pygmt.Figure()
32+
33+
fig.coast(
34+
projection="M10c",
35+
region=[-10, 30, 35, 57],
36+
resolution="l",
37+
land="gray95",
38+
shorelines="1/0.1p,gray50",
39+
borders="1/0.1,gray30",
40+
frame=True,
41+
)
42+
43+
# Add rivers to map
44+
fig.plot(data=gdf, pen="1p,steelblue")
45+
46+
fig.show()

examples/gallery/lines/roads.py

-46
This file was deleted.

0 commit comments

Comments
 (0)