BUG: Incorrect colours when plotting multiple geometry types with list of colours
See original GitHub issueExpected result
I have a geopandas.GeoDataFrame
that contains multiple geometry types (e.g. Polygon
, LineString
and Point
). I want to plot this data by supplying a list of colours (one per feature) to the color=
parameter:
from shapely.geometry import LineString, Point, Polygon
import geopandas as gpd
gdf = gpd.GeoDataFrame(geometry=[Polygon([(1, 1), (1, 2), (2, 2), (2, 1)]),
LineString([(2, 0), (4, 2)]),
Point(3, 2),
Point(1, 0)])
gdf.plot(color=['red', 'green', 'blue', 'blue'])
For this example, I would expect that:
- My
Polygon
feature will be plotted in “red” - My
LineString
feature will be plotted in “green” - Both of my
Point
features will be plotted in “blue”
Actual result
However, I receive this result:
It appears to me like the list of colours is being applied separately to each geometry type, with the first item of each type being plotted in “red”, and the second item of each type being plotted in “green” (e.g. see the Point
features).
This appears related to the PR and linked issues here (#1119), but those look like they refer specifically to multi-geometries, and not multiple geometry types.
Environment
geopandas '0.7.0'
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
IPython 7.12.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Thank you for the report!
Your assumption is correct. Each geometry type is now plotted as an independent Collection, to which we pass
color
as it is (assuming it is a single value). For list-likecolor
values of the correct length, we should do the same we do withvalue
, i.e. decomposing the list based on the geom type.Not necessarily. You can plot geometries without using a
column
and then the idea is that you are able to pass a list of colours that is mapped to individual geometries. It is just broken when you have mixed geom types.That may work, yes. You don’t even need a column as
column
can take an array.But the solution I outlined above would also work: