bokeh_maps.py 文件源码

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

项目:Twitter_Geolocation 作者: shawn-terryah 项目源码 文件源码
def plot_predictions_for_a_city(df, name_of_predictions_col, city):
    '''
    INPUT: DataFrame with location predictions; name of column in DataFrame that 
    contains the predictions; city ('City, State') to plot predictions for
    OUTPUT: Bokeh map that shows the actual location of all the users predicted to
    be in the selected city
    '''

    df_ = df[df[name_of_predictions_col] == city]

    # Initialize two lists to hold all the latitudes and longitudes
    all_lats = []
    all_longs = []

    # Pull all latitudes in 'centroid' column append to all_lats
    for i in df_['centroid']:
        all_lats.append(i[0])

    # Pull all longitudes in 'centroid' column append to all_longs
    for i in df_['centroid']:
        all_longs.append(i[1])

    # Initialize two lists to hold all the latitudes and longitudes 
    # converted to web mercator
    all_x = []
    all_y = []

    # Convert latittudes and longitudes to web mercator x and y format
    for i in xrange(len(all_lats)):
        pnt = transform(
            partial(
                pyproj.transform,
                pyproj.Proj(init='EPSG:4326'),
                pyproj.Proj(init='EPSG:3857')), 
                Point(all_longs[i], all_lats[i]))
        all_x.append(pnt.x)
        all_y.append(pnt.y)

    p = base_plot()
    p.add_tile(STAMEN_TERRAIN)
    p.circle(x=all_x, y=all_y, line_color=None, fill_color='#380474', size=15, alpha=.5)
    output_file("stamen_toner_plot.html")
    show(p)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号