-
Notifications
You must be signed in to change notification settings - Fork 234
Add gallery example for geopandas point geometry (cities in Europe from Natural Earth) #4231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8d41bde
Add gallery example for point geometry
yvonnefroehlich e9ecc3a
Fix typo
yvonnefroehlich 646d06a
Improve intro text
yvonnefroehlich 1b53618
[format-command] fixes
actions-bot 687d043
Remove execution permission
yvonnefroehlich 7438fca
Merge remote-tracking branch 'origin/add-gallery-gp-points' into add-…
yvonnefroehlich c51e8bf
Add code block seperator
yvonnefroehlich 37496ce
Remove geometry column | Adjust variable name | Fix pd warning
yvonnefroehlich bbc77d6
Fix hilighting
yvonnefroehlich 6517b99
Match maximum line length
yvonnefroehlich d58ebc9
Fix higlighting
yvonnefroehlich 3dd4d4a
Merge branch 'main' into add-gallery-gp-points
yvonnefroehlich a775164
Fix highlighting
yvonnefroehlich 81149b6
Fix typo
yvonnefroehlich 1a17f1a
Fix line length
yvonnefroehlich d4db548
Remove borders
yvonnefroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """ | ||
| GeoPandas: Plotting points with Point or MultiPoint geometry | ||
| ============================================================ | ||
|
|
||
| The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as points | ||
| with Point or MultiPoint geometry types stored in a :class:`geopandas.GeoDataFrame` | ||
| object. Use :func:`geopandas.read_file` to load data from any supported OGR format such | ||
| as a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. Then, pass the | ||
| :class:`geopandas.GeoDataFrame` object as an argument to the ``data`` parameter of | ||
| :meth:`pygmt.Figure.plot`, and style the points using the ``fill`` and ``pen`` | ||
| parameters. Additionally, pass suitable columns of the :class:`geopandas.GeoDataFrame` | ||
| to the ``x``, ``y``, and ``text`` parameters of the :meth:`pygmt.Figure.text` method | ||
| to label specific features. | ||
| """ | ||
|
|
||
| # %% | ||
| import geopandas as gpd | ||
| import pygmt | ||
|
|
||
| # Read a sample dataset provided by Natural Earth. The dataset contains cities stored | ||
| # as Point geometry type. In this example we focus on Europe. | ||
| provider = "https://naciscdn.org/naturalearth" | ||
| cities = gpd.read_file(f"{provider}/50m/cultural/ne_50m_populated_places_simple.zip") | ||
| cities = cities[cities["name"] != "Vatican City"].copy() # No overlap with label Rome | ||
| # Create two subsets for small and large cities | ||
| cities_small = cities[cities["worldcity"] != 1].copy() | ||
| cities_large = cities[cities["worldcity"] == 1].copy() | ||
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=[-10, 32.7, 37, 57], projection="M12c", frame=True) | ||
| fig.coast(land="gray95", shorelines="1/0.3p,gray50") | ||
|
|
||
| # Plot the two subsets using squares with different sizes and fills. | ||
| fig.plot(data=cities_small, style="s0.1c", fill="lightgray", pen="0.5p") | ||
| fig.plot(data=cities_large, style="s0.15c", fill="darkorange", pen="0.5p") | ||
|
|
||
| # Label the larger cities with their names. | ||
| fig.text( | ||
| x=cities_large.geometry.x, | ||
| y=cities_large.geometry.y, | ||
| text=cities_large["name"], | ||
| offset="0.12c", | ||
| justify="BL", | ||
| font="6p,Helvetica-Bold", | ||
| fill="white@30", | ||
| pen="0.5p,darkorange", | ||
| clearance="0.05c+tO", | ||
| ) | ||
|
|
||
| fig.show() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.