Eli*_*369 4 python matplotlib marker
我正在尝试在我的绘图上添加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)
Run Code Online (Sandbox Code Playgroud)
但是我收到这个错误:
AttributeError: 'PathCollection' object has no property 'markeredgecolor'
Run Code Online (Sandbox Code Playgroud)
您知道问题是什么以及该怎么办吗?
编辑 - 使用可重现的示例:
#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")
Run Code Online (Sandbox Code Playgroud)
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
)
Run Code Online (Sandbox Code Playgroud)
有了这个配置requirements.txt
geopandas~=0.9.0
matplotlib~=3.3.4
pandas~=1.2.3
shapely~=1.7.1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13869 次 |
| 最近记录: |