3

My question has overlap with Changing colours in GeoPandas?, but unfortunately still unanswered: I want to plot a multiline shapefile in 1 color.

import geopandas as gpd
multiline_example = gpd.read_file('multiline_example_filepath.shp')
multiline_example.plot()

This works fine so far, except that the lines have multiple random colors:

Plot with random colors

Now I simply want to assign 1 color for all lines. Is this possible, and if so, how?

What I found so far:

On the GeoPandas site, some plotting-examples are given (http://geopandas.readthedocs.io/en/latest/mapping.html). Here, they simply use

multiline_example.plot(color='green')

However, if I try this, I get the following error:

TypeError: plot_dataframe() got an unexpected keyword argument 'color'

Why doesn't this work?

I have been able to choose a column (where the color is dependent on the column values), as well as a colormap, but the results are still different colors for different lines.

multiline_example.plot(colormap = 'Greens')
multiline_example.plot(column = 'a_column_name')

Simply by updating from GeoPandas 0.1.1 to 0.3.0.

multiline_example.plot(color='green')

works fine now.

  • 1
    what is your geopandas version ? – Delforge Nov 21 '17 at 11:57
  • That's a good question, I get where things went wrong now.. For some reason I had installed geopandas version 0.1.1. After updating to 0.3.0, everything worked fine. Sorry for bad research from my side, thanks for the clarifying question. – Yannick Mister Nov 22 '17 at 19:49
1

Try creating your own color map with matplotlib:

from matplotlib.colors import ListedColormap

cmap = ListedColormap(['red'], name='allred')
GeoSeries(bldgs).plot(cmap=cmap)

enter image description here

BTW I think I'm using a different version to you as colormap changed to cmap for me (0.3.0).

  • Thanks for the clear answer with example. Found out now that I was using an old version, 0.1.1. After updating everything works as should, a simple plot() already shows 1 color. – Yannick Mister Nov 22 '17 at 19:55
  • No worries. I was having the opposite problem, after upgrading I no longer had colour differentiation so had to add in cmap, edgecolour and alpha to get it working like before. – John Leonard Nov 22 '17 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.