def Make_Map(green_data, zips): sizes = [] for tup in green_data.values(): sizes.append(tup[0]) max_size = max(sizes) colors = [] for tup in green_data.values(): colors.append(tup[1]) max_color = max(colors) for element in green_data.keys(): if element in zips.keys(): #create the data to make a dot for data = {'zip':zips[element][0], 'lat': [(zips[element][1])], 'lon': [(zips[element][2])], \ 'color': [int(255*(green_data[element][1]/max_color)), 255, int(255*(green_data[element][1]/max_color))], \ 'size':50*(int(green_data[element][0])/max_size)} #add the dot for the zipcode geoplotlib.add_layer(dd(data, data['color'], data['size'], f_tooltip=None)) #add labels for zipcode geoplotlib.labels(data, 'zip' , color='k', font_name= 'helvetica', \ font_size=8, anchor_x='left', anchor_y='top') geoplotlib.show()
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")
import geoplotlib from geoplotlib.colors import colorbrewer from geoplotlib.utils import epoch_to_str, BoundingBox, read_csv data = read_csv('./data/metro.csv') geoplotlib.dot(data, 'r') geoplotlib.labels(data, 'name', color=[0, 0, 255, 255], font_size=10, anchor_x='center') geoplotlib.set_bbox(BoundingBox.KBH) geoplotlib.show()
import geoplotlib from geoplotlib.colors import colorbrewer from geoplotlib.utils import epoch_to_str, BoundingBox, read_csv data = read_csv('./data/metro.csv') geoplotlib.dot(data, 'r') geoplotlib.labels(data, 'name', color=[0,0,255,255], font_size=10, anchor_x='center') geoplotlib.set_bbox(BoundingBox.KBH) geoplotlib.show()
f = open("VLOCs.csv", "w+") f.close() #write csv to be read by geoplotlib with open('VLOCs.csv', mode='w', newline='') as VLOCs: VLOCs = csv.writer(VLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) VLOCs.writerow(['name', 'S_lat', 'S_lon', 'D_lat', 'D_lon']) for station in Locations: VLOCs.writerow([station[0], station[1], station[2], station[3], station[4]]) #empty SLOCs.csv f = open("SLOCs.csv", "w+") f.close() #write csv to be read by geoplotlib with open('SLOCs.csv', mode='w', newline='') as SLOCs: SLOCs = csv.writer(SLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) SLOCs.writerow(['name', 'lat', 'lon']) for station in Locations: SLOCs.writerow([station[0], station[1], station[2]]) #plot stations Plotdata1 = read_csv('VLOCs.csv') Plotdata2 = read_csv('SLOCs.csv') gp.set_bbox(BoundingBox(north=9, west=110, south=1, east=95)) gp.graph(Plotdata1, 'S_lat', 'S_lon', 'D_lat', 'D_lon', linewidth=2, color='Blues') gp.dot(Plotdata2, color='blue', point_size=3) gp.labels(Plotdata2, 'name', color='black', font_size=8, anchor_x='center') gp.tiles_provider('positron') gp.show()