Geopandas plot all features same color

时间:2016-04-21 22:28:20

标签: shapely geopandas

Is there any easy way to plot all features in a GeoDataFrame as the same color, rather than the default color map?

Say I have the following geodataframe of linestrings:

>>> import geopandas as gpd
>>> from shapely.geometry import LineString
>>> 
>>> gdf=gpd.GeoDataFrame(geometry=[LineString([(1,2),(4,5)]),LineString([(6,3),(7,3)]),LineString([(6,2),(8,9)])])
>>> gdf
                geometry
0  LINESTRING (1 2, 4 5)
1  LINESTRING (6 3, 7 3)
2  LINESTRING (6 2, 8 9)
>>> 

How can I use gdf.plot() but have all 3 LineStrings show up colored black?

1 个答案:

答案 0 :(得分:2)

由于尚未设置单一颜色,因此您只需使用一种颜色即可创建自己的颜色图。

from matplotlib.colors import ListedColormap    
mycolor = ListedColormap('blue')

对于你的例子,这将导致

import geopandas as gpd
from shapely.geometry import LineString
from matplotlib.colors import ListedColormap    

mycolor = ListedColormap('blue')        
gdf=gpd.GeoDataFrame(geometry=[LineString([(1,2),(4,5)]),LineString([(6,3),(7,3)]),LineString([(6,2),(8,9)])])
gdf.plot(colormap=mycolor)

Figure Result

当然你可以使用任何其他matplotlib颜色。