build_map.py 文件源码

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

项目:crime_prediction 作者: livenb 项目源码 文件源码
def build_map_nmf(df_map, m, coords, info, title, CrimePatterns):
    # 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)
        pc = PatchCollection(df_map[df_map['class'] == i+1]['patches'], match_original=True, alpha=0.8)
        pc.set_facecolor(cmap(norm(df_map.loc[(df_map['class'] == i+1), i].values)))
        ax.add_collection(pc)
    pc = PatchCollection(df_map[df_map['class'] == 0]['patches'], match_original=True, alpha=0.2)
    pc.set_facecolor('grey')
    ax.add_collection(pc)
    x, y = m(coords[0] + 0.02, coords[1] + 1.0)
    details = plt.annotate(info, xy=(x, y), size=24, color='#555555')

    # Draw a map scale
    m.drawmapscale(
        coords[0] + 0.2, coords[1] + 0.95,
        coords[0], coords[1],
        20., fontsize=8,
        barstyle='fancy', labelstyle='simple',
        fillcolor1='w', fillcolor2='#555555',
        fontcolor='#555555', units='mi',
        zorder=5)
    legend_patches = []
    for i in range(6):
        legend_patches.append(mpatches.Patch(color=colors[i],
                                             label=CrimePatterns[i]))
    plt.legend(handles=legend_patches, loc='lower right')
    x1, y1 = m(coords[0] + 0.05, 33.62)
    colorinfo = 'Color represent each cluster of community;\nBrightness represent the severities of crime in each community'
    plt.annotate(colorinfo, xy=(x1, y1), size=16, color='#555555')
    plt.tight_layout()
    fig.set_size_inches(12, 13)
    plt.savefig(title, dpi=300, alpha=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号