gpt4 book ai didi

python - 属性错误 : 'PathCollection' object has no property 'markeredgecolor'

转载 作者:行者123 更新时间:2023-12-05 02:01:33 24 4
gpt4 key购买 nike

我正在尝试在我的绘图上添加 markeredgecolor(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")

最佳答案

Geopandas plot 不接受所有参数作为 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

关于python - 属性错误 : 'PathCollection' object has no property 'markeredgecolor' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66457477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com