-
Notifications
You must be signed in to change notification settings - Fork 1
Figure 6: GeoPandas / spatial data - choropleth map - area with rivers and cities of the states of the USA #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
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 |
Thanks! Also like this map. But Natural Earth does not provide such detailed data of Chicago which can be used for the choropleth part. If we want to have the same datasource for all datasets, we probably will go with the USA example showing the area of the different states with rivers and cities. Now need to think about Alaska. It looks a bit strange when just plotting it together with the rest of the USA. Sometimes Alaska is placed seperatly as an inset; maybe we can do this? Edit: See review by Dongdong #6 (comment) . |
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Fig6_PyGMT_geopandas.py
Outdated
| # Add Alaska and Hawaii separately in the lower left corner | ||
| for xshift, region in zip(["0.9c", "2.3c"], [[172, 230, 51, 72], [-168, -154, 18, 29]]): | ||
| with fig.shift_origin(xshift=xshift): | ||
| fig.plot( | ||
| data=states, | ||
| region=region, | ||
| projection="M2.5c", | ||
| cmap=True, | ||
| pen="0.2p,gray50", | ||
| fill="+z", | ||
| aspatial="Z=area_sqkm" | ||
| ) |
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.
Depending on how we describe this figure in the manuscript, maybe it makes sense to move the code for insets up to the code part for plotting the polygons of the main map (currently line 18).
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.
That would change the region and projection settings and we have to set region and projection again when plotting rivers and cities.
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.
Yes, that's true. We do not use Figure.inset here.
Fig6_PyGMT_geopandas.py
Outdated
| fig = pygmt.Figure() | ||
| fig.basemap(projection="L-96/35/33/41/12c", region=[-126, -66, 25, 49], frame="+n") | ||
|
|
||
| pygmt.makecpt(cmap="bilbao", series=[0, states["area_sqkm"].max()]) |
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.
Maybe use a different CPT or a different range, to avoid polygons that are too light or too dark?
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.
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.
Maybe "hawaii" is better?
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.
Yes, from the CPTs I tested I think "hawaii" is the best (even I am not really a fan of the colors in this colormap itself).
I have chaged the colormap in commit e1121f2. Also played around with a logarithmic scaling, but did not improve the image.
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
|
Just want to let you know, I am considering adding the code for the Chicago map to my personal map repo (please see yvonnefroehlich/gmt-pygmt-plotting#131). As this example relies on a mixture of data sources and uses the geodatasets, I think we will not consider it for the paper or for a tutorial on GeoPandas geometries. So hope this is fine for everybody. |
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
seisman
left a comment
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.
This PR looks good to me.
|
@yvonnefroehlich If you feel this example is good, please copy the codes to Notebook, remove the Python script, output image, then we should be able to merge this PR. |
…ion | Clear output cells












This PR adds a JN for
GeoPandas- spatial data -GeoDataFrame:Preview:
