我想使用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)
当我尝试这个的时候,我得不到一对一。
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)
发布于 2021-08-14 15:43:25
您的“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']
https://stackoverflow.com/questions/59956283
复制相似问题