基于shapefile属性设置Geopandas的线宽,使用Python编程。

5

我想使用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)

图片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

1个回答

1

看起来你的 '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']

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接