def visualize(recs): ''' Takes the direct output from calculation, maps the 3 recommendations based on their cuisine locations ''' if recs != []: rv = [] for idx, tup in enumerate(recs): lat, lon = tup[1]['coordinates'] rv.append(["#" + str(idx + 1) + ". " + tup[1]['name'] + \ " (" + tup[1]['cuisine'] + ")", lat, lon]) header = ['name', 'lat', 'lon'] with open("form/static_files/img/visualization.csv", "w") as csvfile: writer = csv.writer(csvfile) writer.writerow([h for h in header]) writer.writerows(rv) data = geoplotlib.utils.read_csv( "form/static_files/img/visualization.csv") geoplotlib.dot(data) geoplotlib.labels(data, 'name', color=[0, 0, 255, 255], font_size=10, \ anchor_x='center') geoplotlib.savefig("form/static_files/img/visualization")
def geo_dot(file): # file must have at top: name,lat,lon """ Renders a geo dot graph :param file: path to file :return: saves image to temp/map.png """ data = read_csv(file) geoplotlib.dot(data, point_size=3) # geoplotlib.show() geoplotlib.savefig('temp/map')
def geo_spatial(file): """ Renders a geo spatial graph :param file: path to file :return: saves image to temp/spatial.png """ data = read_csv(file) geoplotlib.graph(data, src_lat='lat_departure', src_lon='lon_departure', dest_lat='lat_arrival', dest_lon='lon_arrival', color='hot_r', alpha=16, linewidth=2) # geoplotlib.show() geoplotlib.savefig('temp/spatial')
def makeMap(data): ''' 1. use Kmeans cluster lat and lon of each rsvp event 2. plot them on a world map 3. take a screenshot of the map and save ''' geoplotlib.add_layer(KMeansLayer(data)) geoplotlib.set_smoothing(True) geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.WORLD) geoplotlib.savefig('clustermap') return None
def displayChargers(chargers, color="red", img_name="charging_points"): """ Puts the charging points in a map. Saves image to disk. """ lats, lons, powers = [], [], [] for center in chargers: for charger in center: lats.append(charger["coords"][0]) lons.append(charger["coords"][1]) powers.append(charger["power"]) thedata = pd.DataFrame({"lat": lats, "lon": lons, "powers": powers}) geoplotlib.dot(thedata, color=color) geoplotlib.savefig(img_name) return True
def _draw_hot(day, hour, minute): """ geoplotlib热力图 :param day: :param hour, minute: :param tp: :return: """ data = da.loc_state(day, hour, minute) bbox1 = BoundingBox(north=32, south=30.7, west=122.2, east=120.8) gp.set_bbox(bbox1) # gp.shapefiles('F:\\road_datas\\ShangHai\\boundary', shape_type='empty') gp.kde(data, bw=[0.5, 0.5], cmap='jet', scaling='wjk') gp.savefig('001') gp.show()
def saveGeoData(dataFrame, feature, label, tag): plot_inc_d = {} for inc in dataFrame[feature].unique(): accidents = dataFrame.loc[dataFrame[feature].isin([inc])] plot_inc = {} plot_inc = accidents[['LATITUDE', 'LONGITUDE']] plot_inc.columns = ['lat', 'lon'] for col in plot_inc.columns: plot_inc_d[col] = plot_inc[col].tolist() # Plotting the data w. geoplotlib print label + ":", inc print "Samples:", len(accidents) gpl.kde(plot_inc_d, bw=1, cut_below=2e-4) gpl.set_bbox( BoundingBox(north=40.93, west=-73.85, south=40.53, east=-73.83)) gpl.savefig('geo' + str(tag) + "_" + str(inc)) plot_inc_d = {}
def drawmap(self): """ Multiple examples of kernel density estimation visualization """ data = self.get_dao_object() # geoplotlib.kde(data, bw=5, cut_below=1e-4) # lowering clip_above changes the max value in the color scale # geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1) # different bandwidths geoplotlib.kde(data, bw=20, cmap=self.cmap, cut_below=1e-4) # geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4) # linear colorscale # geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin') geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA')) geoplotlib.savefig(self.ouput_filename)
def plottrack(self, tailnum, airlinecode): frame = self.flightdata frame = frame[[ 'TAIL_NUM', 'OP_UNIQUE_CARRIER', 'FL_DATE', 'ORIGIN_AIRPORT_ID', 'ORIGIN', 'CRS_DEP_TIME', 'DEST_AIRPORT_ID', 'DEST', 'CRS_ARR_TIME' ]] frame = frame.sort_values(['FL_DATE', 'CRS_DEP_TIME'], ascending=True).groupby( ['TAIL_NUM', 'OP_UNIQUE_CARRIER']) alldata = frame.get_group( (tailnum, airlinecode)).reset_index().drop(columns=['index']) origin = alldata['ORIGIN'] dest = alldata['DEST'] mergedata_origin = pd.merge(origin, self.mapdata, left_on=['ORIGIN'], right_on=['name'], how='left') mergedata_origin = mergedata_origin.rename(columns={ 'lat': 'lat_ori', 'lon': 'lon_ori' }) mergedata_origin = mergedata_origin mergedata_dest = pd.merge(dest, self.mapdata, left_on=['DEST'], right_on=['name'], how='left') mergedata_dest = mergedata_dest.rename(columns={ 'lat': 'lat_dest', 'lon': 'lon_dest' }) mergedata_all = pd.concat([mergedata_origin, mergedata_dest], axis=1) geoplotlib.graph(mergedata_all, src_lat='lat_ori', src_lon='lon_ori', dest_lat='lat_dest', dest_lon='lon_dest', color='Reds', linewidth=2) geoplotlib.savefig(tailnum)
import geoplotlib from pandasql import sqldf import pandas as pd df = pd.read_csv('data.csv') destco = pd.read_csv('destination_latlong.csv') orgco = pd.read_csv('origin_latlong.csv') df['FL_DATE'] = pd.to_datetime(df['FL_DATE'], format='%Y-%m-%d') airline = df.set_index('FL_DATE') q = """ SELECT A.ORIGIN_CITY_NAME,A.DEST_CITY_NAME,DC.lat As dlat,DC.lon as dlon,OC.lat As olat,OC.lon as olon FROM airline as A join destco as DC on A.DEST_CITY_NAME=DC.DEST_CITY_NAME join orgco as OC on A.ORIGIN_CITY_NAME=OC.ORIGIN_CITY_NAME WHERE DEP_DELAY=0 AND ARR_DELAY=0; """ print 'working..' result = sqldf(q, locals()) geoplotlib.graph(result, src_lat='olat', src_lon='olon', dest_lat='dlat', dest_lon='dlon', color='rainbow', alpha=32, linewidth=2) geoplotlib.savefig('no delay')
#!/usr/bin/env python2 import geoplotlib from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject data = read_csv('filtered_lonlat.csv') # http://andreacuttone.com/geoplotlib/api.html#module-geoplotlib geoplotlib.dot(data, color=[0,0,0], point_size=1.5) geoplotlib.kde(data, bw=10, cmap='PuBuGn', cut_below=1e-4, clip_above=1e-2, alpha=180) geoplotlib.graph(read_csv('group0.csvgraph.csv'), src_lat='flat', src_lon='flon', dest_lat='tlat', dest_lon='tlon', color=[0,0,0], linewidth=2) geoplotlib.graph(read_csv('group1.csvgraph.csv'), src_lat='flat', src_lon='flon', dest_lat='tlat', dest_lon='tlon', color=[0,255,0], linewidth=2) geoplotlib.graph(read_csv('group2.csvgraph.csv'), src_lat='flat', src_lon='flon', dest_lat='tlat', dest_lon='tlon', color=[128,0,128], linewidth=2) geoplotlib.kde(read_csv('chokepoints.csv'), bw=10, cmap='hot', cut_below=1e-4, clip_above=1e-2, alpha=180) bbox = BoundingBox(north=25.7188,west=-80.280,south=25.711,east=-80.280) geoplotlib.set_bbox(bbox) geoplotlib.set_window_size(1400, 1600) #geoplotlib.set_window_size(700, 800) geoplotlib.tiles_provider('toner') geoplotlib.set_smoothing(True) geoplotlib.savefig('output') #geoplotlib.show()
data = crime_data_2017_DF.loc[crime_data_2017_DF['Resolved'] == 'Resolved',['Category','X','Y']] data = data.rename(columns={"Category":"name", "X":"lon", "Y":"lat"}) data.to_csv("../data/GraphData_2017.csv", encoding="utf-8", index=False) data.head() data = read_csv('../data/GraphData_2017.csv') # In[117]: geoplotlib.dot(data) geoplotlib.savefig('../plot/22.AllCrimes_2017') #geoplotlib.show() # # Map plot for Unresolved Arson : 2017 vs. 2016 (using Folium) # In[118]: crime_data_2016_unresolvedArson_DF = crime_data_2016_DF.loc[ (crime_data_2016_DF['Resolved'] == 'Unresolved') & (crime_data_2016_DF['Category'] == 'ARSON'), :] crime_data_2017_unresolvedArson_DF = crime_data_2017_DF.loc[
""" Multiple examples of kernel density estimation visualization """ import geoplotlib from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject data = read_csv('data/opencellid_dk.csv') #geoplotlib.kde(data, bw=5, cut_below=1e-4) # lowering clip_above changes the max value in the color scale #geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1) # different bandwidths geoplotlib.kde(data, bw=20, cmap='OrRd', cut_below=1e-4) #geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4) # linear colorscale #geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin') geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA')) geoplotlib.savefig('full.png') geoplotlib.show()