Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'PathCollection' object has no property 'markeredgecolor'

I'm trying to add markeredgecolor on my plot (marker='.' and I want markers to be surrounded by different colors depending on their characteristics).

I tried to do like this with geographic data : https://python-graph-gallery.com/131-custom-a-matplotlib-scatterplot/

fig, ax = plt.subplots(figsize = (8,6)) 
df.plot(ax=ax,color='green', marker=".", markersize=250)
df2.plot(ax=ax,color='green', marker=".", markerfacecolor="orange", markersize=250)

However I get this error :

AttributeError: 'PathCollection' object has no property 'markeredgecolor'

Do you know what's the problem and what to do ?

Edit - with a reproducible example :

#Packages needed
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
import shapely.wkt

#Creating GeoDataFrame df2
df2 = pd.DataFrame([shapely.wkt.loads('POINT (7.23173 43.68249)'),shapely.wkt.loads('POINT (7.23091 43.68147)')])
df2.columns=['geometry']
df2 = gpd.GeoDataFrame(df2)
df2.crs = {'init' :'epsg:4326'}

#Ploting df2
fig, ax = plt.subplots()
df2.plot(ax=ax,color='green', marker=".", markerfacecolor="orange")
like image 669
Elise1369 Avatar asked Sep 06 '25 03:09

Elise1369


1 Answers

Geopandas plot does not accept all arguments as matplotlib.plot (reference [here])(https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.GeoDataFrame.plot.html)

However, there is some **style_kwds that can do the work for you (not clearly explained in the docs though):

Taking back your code

df2.plot(
    ax=ax,
    color='green',
    marker=".",
    markersize=1000,
    edgecolor='orange', # this modifies the color of the surrounding circle
    linewidth=5 # this modifies the width of the surrounding circle
)

Having this configuration in requirements.txt

geopandas~=0.9.0
matplotlib~=3.3.4
pandas~=1.2.3
shapely~=1.7.1
like image 173
dynnammo Avatar answered Sep 07 '25 17:09

dynnammo