【发布时间】:2021-03-03 12:51:50
【问题描述】:
我正在尝试在我的绘图上添加 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")
【问题讨论】:
-
我认为你的代码是pandas提供的绘图功能,它没有标记边缘的颜色。你指的是maplotlib。
-
您使用的是什么版本的 pandas 和 matplotlib?这对我有用
-
感谢您的回答! @r-beginners 你的意思是我没有在这里使用 matplotlib,对吧? (我不明白为什么有两种方法可以在 Python 上做图,一定是这样!)
-
@DavidG 我在 pandas 1.1.3 和 matplotlib 3.3.1 上。你呢?
-
这种版本组合也适用于我。你能创建一个minimal reproducible example吗?
标签: python matplotlib marker