python - 在地图上绘制图形点,但错误代码为“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 不确定为什么加载图形有效,但添加的点使其中断。
如果可以的话,只是寻找对此的理解和修复。谢谢
解决方案
我简单地设置了这个问题gdf.plot(aspect=1)
。它在以前版本的 geopandas 中没有发生,但它突然开始发生,我认为它只是这个参数,因为它可以在你给出的错误中读取。
推荐阅读
- c# - 使用modbus进行异步设备通信的问题
- vim - 自定义语法高亮无法通过 ~/.vimrc
- android - Kotlin、Coroutines、Kodein 和 RecyclerView 列表
- c - 将包含浮点数的结构转换为对网络更友好的结构
- javascript - 复制 dataLayer 正在返回 {object Object}
- substrate - 基板中的事件存储成本是多少?
- sed - 如何附加文件 n 次并使用 sed 对块进行编号?
- r - 在数据框中创建一个作为总和、按类别或不同变量的新列。(我曾经在 STATA 中使用 bysort egen total 执行此操作)
- postgresql - 在 postgresql 的函数中的输入参数中转义单引号
- r - 将三个数据框的内容合并到 R 中的一列(跨多列)