2012-11-07 46 views
0

我在道路网络等的matplotlib中创建了一些GIS风格的地块,所以我使用LineCollection来存储和表示相应的所有道路和颜色。这是工作的罚款,我基于色彩的一个标准,道路和以下地图:matplotlib集合线宽映射?

from matplotlib.colors import ListedColormap,BoundaryNorm 
from matplotlib.collections import LineCollection 

cmap = ListedColormap(['grey','blue','green','yellow','orange','red','black']) 
norm = BoundaryNorm([0,0.5,0.75,0.9,0.95,1.0,1.5,100],cmap.N) 

roads = LineCollection(road_segments, array=ratios, cmap=cmap, norm=norm) 
axes.add_collection(roads) 

这工作得很好,但我真的想有一个类似的方式,以彩色地图定义线宽 - 从0.5到每种颜色5个

有没有人知道这样做的一个聪明的方法?

回答

0

该关键字为linewidths

import matplotlib.pyplot as plt 
from matplotlib.collections import LineCollection 

axes = plt.axes() 

roads = LineCollection([ 
         [[0, 0], [1, 1]], 
         [[0, 1], [1, 0]] 
         ], 
         colors=['black', 'red'], 
         linewidths=[3, 8], 
         ) 
axes.add_collection(roads) 

plt.show() 

HTH