Hi, I am trying to make a choropleth map from a shapefile using pygmt. I followed one answer on how to plot polygons using pygmt from geodataframe, but when I specify color=gdf.aal_com
to color each polygon by column vasues I get an error:
GMTInvalidInput: Can’t use arrays for color if data is matrix or file.
import geopandas as gpd
import pygmt
import os
#%%
gdf = gpd.read_file('../Albania_loss.shp')
gdf.head()
hex_id | pop | square_pop | NAME_0 | aal_com | geometry | |
---|---|---|---|---|---|---|
0 | 7310 | 9749.987529 | 98.742025 | Albania | 41208.410919 | POLYGON ((19.58093 40.88737, 19.52319 40.88737… |
1 | 8112 | 476.375406 | 21.826026 | Albania | 3317.674009 | POLYGON ((20.01394 40.13737, 19.95620 40.13737… |
# collect extent region
bound = gdf.total_bounds
region = [bound[0], bound[2], bound[1], bound[3]]
# write to (tmp) file
# !geopandas (fiona) is not able to overwrite this format
filename = '../albania.gmt'
gdf.to_file(filename, driver='OGR_GMT')
# plot
fig = pygmt.Figure()
fig.basemap(region=region, projection="M20c", frame=True)
fig.plot(data='albania.gmt',color=gdf.aal_com)
fig.show(method='external')
Is there another way to achieve like the following in pygmt?