def _draw_segments(data, ax, **params):
"""
Draw independent line segments between all the
points
"""
color = to_rgba(data['color'], data['alpha'])
# All we do is line-up all the points in a group
# into segments, all in a single list.
# Along the way the other parameters are put in
# sequences accordingly
indices = [] # for attributes of starting point of each segment
segments = []
for _, df in data.groupby('group'):
idx = df.index
indices.extend(idx[:-1]) # One line from two points
x = data['x'].iloc[idx]
y = data['y'].iloc[idx]
segments.append(make_line_segments(x, y, ispath=True))
segments = np.vstack(segments)
if color is None:
edgecolor = color
else:
edgecolor = [color[i] for i in indices]
linewidth = data.loc[indices, 'size']
linestyle = data.loc[indices, 'linetype']
coll = mcoll.LineCollection(segments,
edgecolor=edgecolor,
linewidth=linewidth,
linestyle=linestyle,
zorder=params['zorder'])
ax.add_collection(coll)
评论列表
文章目录