AttributeError:“PathCollection”对象没有属性“MarkerEdge颜色”

2024-05-16 18:55:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在绘图中添加MarkerEdge颜色(marker='.',我希望标记根据其特征被不同的颜色包围)

我试图用地理数据这样做: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)

但是我得到了这个错误:

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

你知道有什么问题吗?怎么办

编辑-使用可复制的示例:

#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")

Tags: importplotmatplotlib颜色asfigpltgreen
1条回答
网友
1楼 · 发布于 2024-05-16 18:55:11

Geopandasplot不接受所有参数作为matplotlib.plot(引用[此处])(https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.GeoDataFrame.plot.html

但是,有一些**style_kwds可以为您完成这项工作(尽管文档中没有明确说明):

收回你的代码

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
)

requirements.txt中具有此配置

geopandas~=0.9.0
matplotlib~=3.3.4
pandas~=1.2.3
shapely~=1.7.1

相关问题 更多 >