sf_map.py 文件源码

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

项目:crime_prediction 作者: livenb 项目源码 文件源码
def plot_map(m, coords, df_map, info, savefig=False):
    plt.clf()
    fig = plt.figure()
    ax = fig.add_subplot(111, axisbg='w', frame_on=True)
    # draw wards with grey outlines
    norm = Normalize()
    for i in xrange(5):
        color = colormaps[i]
        cmap = plt.get_cmap(color)
        cond = (df_map['class'] == (i+1))
        inx = df_map[cond].index
        if cond.sum() > 0:
            pc = PatchCollection(df_map[cond]['patches'],
                                 match_original=True, alpha=0.75)
            pc.set_facecolor(cmap(norm(df_map.loc[inx, 'cls_%d'%(i+1)].values)))
            ax.add_collection(pc)
    if (df_map['class'] == 0).sum() > 0:
        pc = PatchCollection(df_map[df_map['class'] == 0]['patches'],
                             match_original=True, alpha=0.1
                             )
        pc.set_facecolor('grey')
        ax.add_collection(pc)
    x, y = m(coords[0], coords[3]+0.006)

    details = ax.annotate(info, xy=(x, y), size=20, color='k')

    # Draw a map scale
    m.drawmapscale(
        coords[0]+0.02, coords[1]-0.004,
        coords[0], coords[1],
        2,
        barstyle='fancy', labelstyle='simple',
        fillcolor1='w', fillcolor2='#555555',
        fontcolor='#555555', units='mi',
        zorder=5)

    legend_patches = []
    for i in range(5):
        legend_patches.append(mpatches.Patch(color='C%d' % i,
                                             label=classes[i]))
    ax.legend(handles=legend_patches, loc='upper right')

    fig.set_size_inches(12, 12)
    plt.tight_layout()
    if savefig:
        plt.savefig(savefig, dpi=200, alpha=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号