map_viz.py 文件源码

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

项目:ms_deisotope 作者: mobiusklein 项目源码 文件源码
def draw_features(features, ax=None, alpha=0.65, width=2e-5, **kwargs):
    if ax is None:
        fig, ax = plt.subplots(1)

    ellipses = []
    kwargs.setdefault("lw", 0.05)
    lw = kwargs.get("linewidth", kwargs.get("lw"))
    for feat in features:
        if feat is None:
            continue
        center = (feat.end_time + feat.start_time) / 2.
        height = feat.end_time - feat.start_time

        center_mz = feat.mz
        mz_width = center_mz * width

        ellipses.append(
            FancyBboxPatch((feat.mz - mz_width / 4., center - height / 2.), width=mz_width / 2., height=height,
                           boxstyle=mpatches.BoxStyle.Round(pad=mz_width / 2.)))

    for ell in ellipses:
        ell.set_alpha(alpha)
        ell.set_facecolor("blue")
        ell.set_edgecolor("blue")
        ell.set_linewidth(lw)
        ax.add_artist(ell)

    ax.set_xlim(
        min(features, key=lambda x: x.mz if x is not None else float('inf')).mz - 1,
        max(features, key=lambda x: x.mz if x is not None else -float('inf')).mz + 1)
    ax.set_ylim(
        min(features, key=lambda x: x.start_time if x is not None else float('inf')).start_time - 1,
        max(features, key=lambda x: x.end_time if x is not None else -float('inf')).end_time + 1)
    return ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号