Top_Trending.py 文件源码

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

项目:Trending-Places-in-OpenStreetMap 作者: geometalab 项目源码 文件源码
def plot_graphs(df, trending_daily, day_from, day_to, limit, country_code, folder_out=None):
    days = pd.DatetimeIndex(start=day_from, end=day_to, freq='D')
    for day in days:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        plt.rc('lines', linewidth=2)
        data = trending_daily.get_group(str(day.date()))
        places, clusters = top_trending(data, limit)
        for cluster in clusters:
            places.add(max_from_cluster(cluster, data))
        ax.set_prop_cycle(plt.cycler('color', ['r', 'b', 'yellow'] + [plt.cm.Accent(i) for i in np.linspace(0, 1, limit-3)]
                                     ) + plt.cycler('linestyle', ['-', '-', '-', '-', '-', '--', '--', '--', '--', '--']))
        frame = export(places, clusters, data)
        frame.sort_values('trending_rank', ascending=False, inplace=True)
        for i in range(len(frame)):
            item = frame.index[i]
            lat, lon, country = item
            result_items = ReverseGeoCode().get_address_attributes(lat, lon, 10, 'city', 'country_code')
            if 'city' not in result_items.keys():
                mark = "%s (%s)" % (manipulate_display_name(result_items['display_name']),
                                    result_items['country_code'].upper() if 'country_code' in result_items.keys() else country)
            else:
                if check_eng(result_items['city']):
                    mark = "%s (%s)" % (result_items['city'], result_items['country_code'].upper())
                else:
                    mark = "%.2f %.2f (%s)" % (lat, lon, result_items['country_code'].upper())
            gp = df.loc[item].plot(ax=ax, x='date', y='count', label=mark)
        ax.tick_params(axis='both', which='major', labelsize=10)
        ax.set_yscale("log", nonposy='clip')
        plt.xlabel('Date', fontsize='small', verticalalignment='baseline', horizontalalignment='right')
        plt.ylabel('Total number of views (log)', fontsize='small', verticalalignment='center', horizontalalignment='center', labelpad=6)
        gp.legend(loc='best', fontsize='xx-small', ncol=2)
        gp.set_title('Top 10 OSM trending places on ' + str(day.date()), {'fontsize': 'large', 'verticalalignment': 'bottom'})
        plt.tight_layout()
        db = TrendingDb()
        db.update_table_img(plt, str(day.date()), region=country_code)
        plt.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号