首页 > 解决方案 > 在地图上绘制图形点,但错误代码为“ValueError: 'box_aspect' and 'fig_aspect' must be positive”

问题描述

我正在尝试将一组点绘制到华盛顿州金县的图形上。

我可以使用以下代码显示图形:

fig, ax = plt.subplots(figsize = (15,15))
kings_county.plot(ax=ax)

这给了我图形。然后我从我加载的 csv 的纬度/经度中读取点。

df = pd.read_csv('kc_house_data_train.csv')
crs = {'init': 'epsg:4326'}

这将所有点放在一个新的数据框中

geometry = [Point(x,y) for x,y in zip(df.lat,df.long)]

geo_df = gpd.GeoDataFrame(df, # specifify your dataframe
                          crs = crs, # this is your coordinate system
                          geometry = geometry) # specify the geometry list we created

但是,当我这样做时

fig, ax = plt.subplots(figsize = (40,40))
kings_county.plot(ax=ax, alpha = 0.4, color = 'grey', aspect = 'auto')
geo_df[geo_df.price >= 750000].plot(ax = ax , markersize = 20, color = 'blue',marker = 'o',label = 'pricey')
geo_df[geo_df.price < 750000].plot(ax = ax , markersize = 20, color = 'blue',marker = 'o',label = 'pricey')
plt.legend()

它只是返回一个错误:ValueError: 'box_aspect' and 'fig_aspect' must be positive 不确定为什么加载图形有效,但添加的点使其中断。

如果可以的话,只是寻找对此的理解和修复。谢谢

标签: pythonmatplotlibaspect-ratio

解决方案


我简单地设置了这个问题gdf.plot(aspect=1)。它在以前版本的 geopandas 中没有发生,但它突然开始发生,我认为它只是这个参数,因为它可以在你给出的错误中读取。


推荐阅读