基于geopandas、python的shapefile属性的线宽

2024-09-28 22:26:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用geopandas绘制一个shapefile。我想根据shapefile中的属性获得线条的厚度。我正在为此使用以下命令:

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)

这意味着厚度和色码应相互匹配

我试过这个:

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=1, edgecolor='0.8', vmin=0, vmax=1)

Image 1

当我尝试这个时,我没有得到一对一的答案

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)

Image 2


Tags: plot绘制columncmapgeopandasshapefileshp厚度
1条回答
网友
1楼 · 发布于 2024-09-28 22:26:10

看起来您的“Case1_2”属性不是数字,或者在有意义地更改线宽的范围内不是数字。您可能只对0到15之间的线宽感兴趣。如果创建基于数字的新属性(例如,基于流顺序),则使用列值设置线宽应该有效

shp_sub['order'] = 1. # best to be numeric, not a geometry
shp_sub['order'].iloc[10] = 4. # change the value of one of the attributes
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5),
             linewidth=shp_sub['order'], edgecolor='0.8', # edgecolor another column with data?
             vmin=0, vmax=1)

或者,可以将现有列中的一列缩放到有用的线宽范围内:

import numpy as np
temp_array = shp_sub['Case1_2'].values
# Scale from 0 to 1
temp_array = (np.max(temp_array)-temp_array)/(np.max(temp_array)-np.min(temp_array))

max_width = 10 # set maximum line width to use

shp_sub['lw'] = max_width*temp_array
# and then plot with linewidth=shp_sub['lw']

相关问题 更多 >