I preparing some choropleth election result maps in Geopandas. The assigned color for each electoral district must correspond with the winning party (a color that I pre-determine), and the intensity of the color (opacity, saturation, etc) must be adjusted based some variable such as the margin of victory. Basically your traditional post-election map job.
My GeoDataFrame is structured as such (note there are three or more parties):
district_no winning_party color margin geom 0 Conservative #C62828 .56 POLYGON(599240.6488817427....) 1 Conservative #C62828 .78 POLYGON(589240.6488427823....) 2 Liberal #283593 .34 POLYGON(563405.6788424563....) 3 Conservative #C62828 .08 POLYGON(563405.6488424563....) 4 Labour #FF9800 .22 POLYGON(583405.6918424563....) 5 Labour #FF9800 .37 POLYGON(633405.6128424563....) 6 Liberal #283593 .48 POLYGON(533405.6278424563....) etc... etc... etc... etc... etc...
I have not been able to figure out how to achieve this with the
.plot() method. The argument 'color' simply applies the inputted color to all rows, and I am unsure how using
cmap would help me achieve this, especially given that I must also adapt the color intensity based the margin column.
The only solution I can conceive is to loop through each row in the GeoDataFrame, and one by one plot out each polygon by assigning the color column value to the color argument, and then use the margin value to adjust the alpha level. Then somehow, I would have to merge/append all the plots back together to rebuild a final map (I'm not even sure this is possible).
Surely there is a better way than this. I have scoured the Internet, but surprisingly, I cannot find any solutions for this multi-party choropleth maps. Any ideas?.