geom_path.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:plotnine 作者: has2k1 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号