-
Notifications
You must be signed in to change notification settings - Fork 1
Figure 6: GeoPandas #6
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
base: main
Are you sure you want to change the base?
Conversation
|
Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/GenericMappingTools/pygmt-paper-figures/pull/6 |
|
I'm unsure if we need this example. As I understand it, PyGMT can plot GeoPandas objects, but its functionality for processing them is limited since the aspatial metadata will be lost during processing. |
I think the idea of having a choropleth map is, to show that there is functionality extending the feature available in GMT. |
|
This example highlights GeoPandas integration in PyGMT. A The script below plots three different datasets (available from https://www.naturalearthdata.com/) with different geometrie.
So, only MultiLineString is not covered. import pygmt
import geopandas as gpd
world = gpd.read_file("https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip")
rivers = gpd.read_file("https://naciscdn.org/naturalearth/110m/physical/ne_110m_rivers_lake_centerlines.zip")
cities = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_populated_places_simple.zip")
world["POP_EST"] *= 1.0e-5
fig = pygmt.Figure()
fig.basemap(region="=SA", projection="M15c", frame=True)
fig.plot(data=world, pen="0.5p,black", fill="lightgreen")
pygmt.makecpt(cmap="turbo", series=(0, 3000, 100))
fig.plot(
data=world,
pen="0.2p,gray10",
fill="+z",
cmap=True,
aspatial="Z=POP_EST",
)
fig.colorbar(frame=True)
fig.plot(data=rivers, pen="1p,blue")
fig.plot(data=cities, style="c0.1c", fill="red", pen="black")
fig.text(x=cities.geometry.x, y=cities.geometry.y, text=cities["name"], font="10p,Helvetica-Bold,black", offset="0.2c/0.2c")
fig.show()
|
|
Your example looks quite promising, but I get the following error when running the code:
Will look it in detail tomorrow or within the next days. |
|
It's likely because the city names contain non-ASCII characters, which doesn't work well in your console. This is a likely solution for you: cities["name"] = cities["name"].apply(lambda x: x.encode("utf-8", errors="ignore").decode("utf-8")) |
Oh, thanks! I already tried something similar, but it did solve the problem yet. For now, I focus on the |
| rivers = gpd.read_file("https://naciscdn.org/naturalearth/110m/physical/ne_110m_rivers_lake_centerlines.zip") | ||
| cities = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_populated_places_simple.zip") | ||
|
|
||
| world["POP_EST"] *= 1.0e-5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Express the population in millions.
| world["POP_EST"] *= 1.0e-5 | |
| world["POP_EST"] *= 1.0e-6 |
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=region, projection="M15c", frame=True) | ||
| pygmt.makecpt(cmap="batlow", series=(0, 2700, 100)) # 30000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pygmt.makecpt(cmap="batlow", series=(0, 2700, 100)) # 30000 | |
| pygmt.makecpt(cmap="batlow", series=(0, 270, 10)) # 30000 |
| cmap=True, | ||
| aspatial="Z=POP_EST", | ||
| ) | ||
| fig.colorbar(frame=["x+lPopulation", "y+l*10e-5"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fig.colorbar(frame=["x+lPopulation", "y+l*10e-5"]) | |
| fig.colorbar(frame=["x+lPopulation (millions)"]) |



This PR adds a JN for
GeoPandas- spatial data -GeoDataFrame:penparametercmap,aspatialparameters