예제 #1
0
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()
예제 #2
0
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
예제 #3
0
def draw_grid(nodes, unfiltered=None):
    """
    Draw grid using computed nodes.

    Args:
        nodes (numpy.ndarray): Data points to plot
        unfiltered (numpy.ndarray): Unfiltered data points. If not None,
        plot using different color.
    """

    # Layer for plotting the nodes
    class PointsLayer(BaseLayer):
        def __init__(self, data, color, point_size):
            self.data = data
            self.color = color
            self.point_size = point_size

        def invalidate(self, proj):
            x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
            self.painter = BatchPainter()
            self.painter.set_color(self.color)
            self.painter.points(x, y, point_size=self.point_size, rounded=True)

        def draw(self, proj, mouse_x, mouse_y, ui_manager):
            self.painter.batch_draw()

    # Get grid node data into dict format.
    data_grid = {'lat': nodes[:, 0], 'lon': nodes[:, 1]}

    # If unfiltered nodes specified, get data into dict format.
    if unfiltered is not None:
        data_unfiltered = {'lat': unfiltered[:, 0], 'lon': unfiltered[:, 1]}

    # If unfiltered nodes specified, plot on layer.
    if unfiltered is not None:
        geoplotlib.add_layer(
            PointsLayer(data_unfiltered, color=[255, 0, 0], point_size=4))

    # Plot grid nodes.
    geoplotlib.add_layer(
        PointsLayer(data_grid, color=[0, 0, 255], point_size=7))

    # Set bounding box and show.
    geoplotlib.set_bbox(
        BoundingBox(north=40.897994,
                    west=-73.199040,
                    south=40.595581,
                    east=-74.55040))
    geoplotlib.show()
예제 #4
0
"""
Example of delaunay triangulation
"""
from geoplotlib.layers import DelaunayLayer
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox

data = read_csv('data/bus.csv')
geoplotlib.add_layer(DelaunayLayer(data, cmap='hot_r'))
geoplotlib.set_bbox(BoundingBox.DK)
geoplotlib.set_smoothing(True)
geoplotlib.show()
예제 #5
0
    def bbox(self):
        """
        Return the bounding box for this layer
        """
        return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])

    def on_key_release(self, key, modifiers):
        """
        Override this method for custom handling of keystrokes
        :param key: the key that has been released
        :param modifiers: the key modifiers
        :return: True if the layer needs to call invalidate
        """
        return False

if __name__ == '__main__':
    # TESTING plots a few hurricane paths using the python geoplotlib library
    df = pd.read_csv("simpdata.csv", low_memory=False)
    # names = df.dtypes.index
    # print(names)
    lat = df['Latitude_for_mapping']
    long = df['Longitude_for_mapping']
    # print("lat", (lat[0]))
    # print("long", long)
    numindex = np.arange(long.size)
    # print(numlong)
    # print(numlat)
    lst = DataAccessObject({'lon': long, 'lat': lat})
    # print(lst)
    geoplotlib.add_layer(LineLayer(lst, numindex))
    geoplotlib.show()
예제 #6
0
        self.painter = BatchPainter()

    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter = BatchPainter()
        df = self.data.where((self.data['timestamp'] > self.t)
                             & (self.data['timestamp'] <= self.t + 15 * 60))

        for taxi_id in set(df['taxi_id']):
            grp = df.where(df['taxi_id'] == taxi_id)
            self.painter.set_color(self.cmap[taxi_id])
            x, y = proj.lonlat_to_screen(grp['lon'], grp['lat'])
            self.painter.points(x, y, 10)

        self.t += 2 * 60

        if self.t > self.data['timestamp'].max():
            self.t = self.data['timestamp'].min()

        self.painter.batch_draw()
        ui_manager.info(epoch_to_str(self.t))

    def bbox(self):
        return BoundingBox(north=40.110222,
                           west=115.924463,
                           south=39.705711,
                           east=116.803369)


geoplotlib.add_layer(TrailsLayer())
geoplotlib.show()
예제 #7
0
import geoplotlib
from geoplotlib.utils import epoch_to_str, BoundingBox, read_csv


class TrailsLayer(BaseLayer):

    def __init__(self):
        self.data = read_csv('data/taxi.csv')
        self.data = self.data.where(self.data['taxi_id'] == list(set(self.data['taxi_id']))[2])
        self.t = self.data['timestamp'].min()
        self.painter = BatchPainter()


    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter = BatchPainter()
        self.painter.set_color([0,0,255])
        df = self.data.where((self.data['timestamp'] > self.t) & (self.data['timestamp'] <= self.t + 30*60))
        proj.fit(BoundingBox.from_points(lons=df['lon'], lats=df['lat']), max_zoom=14)
        x, y = proj.lonlat_to_screen(df['lon'], df['lat'])
        self.painter.linestrip(x, y, 10)
        self.t += 30
        if self.t > self.data['timestamp'].max():
            self.t = self.data['timestamp'].min()

        self.painter.batch_draw()
        ui_manager.info(epoch_to_str(self.t))


geoplotlib.add_layer(TrailsLayer())
geoplotlib.show()
예제 #8
0
"""
Example of delaunay triangulation
"""
from geoplotlib.layers import DelaunayLayer
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox


data = read_csv('data/bus.csv')
geoplotlib.add_layer(DelaunayLayer(data, cmap='hot_r'))
geoplotlib.set_bbox(BoundingBox.DK)
geoplotlib.set_smoothing(True)
geoplotlib.show()
예제 #9
0
        self.painter.points(x[self.frame_counter], y[self.frame_counter], 2*self.point_size, False)
        
        self.painter.batch_draw()
        picked = self.hotspots.pick(mouse_x, mouse_y)
        if picked:
            ui_manager.tooltip(picked)
        self.frame_counter += 1
        time.sleep(0.4)
        if self.frame_counter == len(x):
            self.frame_counter = 0


    def bbox(self):
        return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
        
geoplotlib.add_layer(DotDensityLayer(points_df))
#geoplotlib.show()

# Custom layer
# crash on five million
trajectories_graph = mdf

trajectories_graph.loc[:, 'dest_lat'] = trajectories_graph.shift(-1).loc[:, 'lat']
trajectories_graph.loc[:, 'dest_lon'] = trajectories_graph.shift(-1).loc[:, 'lon']
trajectories_graph = trajectories_graph[:-1]

# Edge colors are based on distance between points
geoplotlib.graph(trajectories_graph, src_lat='lat', src_lon='lon', dest_lat='dest_lat', dest_lon='dest_lon', linewidth=80, alpha=255)
geoplotlib.show()
#trajectories[self.frame_counter]
예제 #10
0
        
        # If saving frames.
        if self.save_frames:
            GeoplotlibApp.screenshot(f'./results/animation_frames/{self.count}.png')


if __name__ == '__main__':

    ### PARSE ARGUMENTS ###
    parser = argparse.ArgumentParser(description='Animate lists of edge lists.')
    parser.add_argument('--network-path', type=str, required=True, help='Path to the network corresponding to the edge list')
    parser.add_argument('--edgelist-path', type=str, required=True, help='Path to the edge list')
    parser.add_argument('--show-addresses', action='store_true', help='Show addresses corresponding to the nodes')
    parser.add_argument('--save-frames', action='store_true', help='Save animation frames')
    parser.add_argument('--line-width', type=float, default=1.3, help='Width of the lines representing the edges')
    args = parser.parse_args()
    #######################

    # Parse network.
    network = nx.read_gpickle(args.network_path)

    # Parse edgelist.
    edgelists = np.load(args.edgelist_path, allow_pickle=True)

    # Add animation layer, set bounding box and show.
    geoplotlib.add_layer(AnimatedProcess(network, edgelists, show_addresses=args.show_addresses, 
        save_frames=args.save_frames, line_width=args.line_width))
    geoplotlib.set_bbox(BoundingBox(north=40.897994, west=-73.199040, south=40.595581, east=-74.55040))
    geoplotlib.show()

예제 #11
0
def draw_geo():
    data = geoplotlib.utils.read_csv('../data/des.csv')
    geoplotlib.add_layer(KMeansLayer(data))
    geoplotlib.set_smoothing(True)
    geoplotlib.show()
예제 #12
0
        k_means.fit(np.vstack([x,y]).T)
        labels = k_means.labels_

        self.cmap = create_set_cmap(set(labels), 'hsv')
        for l in set(labels):
            self.painter.set_color(self.cmap[l])
            self.painter.convexhull(x[labels == l], y[labels == l])
            self.painter.points(x[labels == l], y[labels == l], 2)
    
            
    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        ui_manager.info('Use left and right to increase/decrease the number of clusters. k = %d' % self.k)
        self.painter.batch_draw()


    def on_key_release(self, key, modifiers):
        if key == pyglet.window.key.LEFT:
            self.k = max(2,self.k - 1)
            return True
        elif key == pyglet.window.key.RIGHT:
            self.k = self.k + 1
            return True
        return False
  

data = geoplotlib.utils.read_csv('data/bus.csv')
geoplotlib.add_layer(KMeansLayer(data))
geoplotlib.set_smoothing(True)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()
예제 #13
0
        self.t = self.data['timestamp'].min()
        self.painter = BatchPainter()


    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter = BatchPainter()
        df = self.data.where((self.data['timestamp'] > self.t) & (self.data['timestamp'] <= self.t + 24*3600)) #set minimum time interval
        
        for name in set(df['name']):
            grp = df.where(df['name'] == name)
            self.painter.set_color('blue') #set color, default: self.cmap[name]
            x0, y0 = proj.lonlat_to_screen(grp['Slon'], grp['Slat'])
            x1, y1 = proj.lonlat_to_screen(grp['Flon'], grp['Flat'])
            self.painter.points(x0, y0, 3)
            self.painter.lines(x0,y0,x1,y1,width=3)

        self.t += 24*3600 #set animation step size

        if self.t > self.data['timestamp'].max():
            self.t = self.data['timestamp'].min()

        self.painter.batch_draw()
        ui_manager.info(epoch_to_str(self.t))


    def bbox(self):
        return BoundingBox(north=9, west=110, south=1, east=95) #set boundingbox


gp.add_layer(TrailsLayer())
gp.show()
예제 #14
0
	threedee = plt.figure().gca(projection='3d')
	data['color'] = np.where((data['user_ratings_total'] > data['user_ratings_total'].mean()) & (data['rating'] > data['rating'].mean()) & (data['occupancy_index'] < data['occupancy_index'].mean()), 'red', 'green')
	threedee.scatter(data['user_ratings_total'], data['rating'], data['occupancy_index'], c=data['color'] ,cmap=cmap)
	threedee.set_xlabel('user_ratings_total')
	threedee.set_ylabel('rating')
	threedee.set_zlabel('occupancy_index')
	
	# Set fullscreen
	mng = plt.get_current_fig_manager()
	
	if plt.get_backend() == 'TkAgg':
		mng.window.state('zoomed')
		
	if plt.get_backend() == 'wxAgg':
		mng.frame.Maximize(True)
	
	if plt.get_backend() == 'Qt4Agg':
		figManager.window.showMaximized()
	
	plt.show()
	
	cheaters = np.where(data['color'] == 'red')
	cheaters = data.iloc[cheaters]
	
	cheaters.to_json('results/cheaters.json')

	geoplotlib.add_layer(CustomLayer(geoplotlib.utils.DataAccessObject(data), color=[0, 255, 0, 60], point_size=4))
	geoplotlib.add_layer(CustomLayer(geoplotlib.utils.DataAccessObject(cheaters), color=[255, 0, 0], point_size=4, f_tooltip=lambda r: r['name']))
	
	geoplotlib.show()
예제 #15
0
        while len(queue) > 0:
            qt = queue.pop()
            if qt.can_split(x, y):
                queue.extend(qt.split())
            else:
                done.append(qt)

        print((len(queue), len(done)))

        if self.cmap is not None:
            for qt in done:
                area = (qt.right - qt.left) * (qt.top - qt.bottom)
                self.painter.set_color(
                    self.cmap.to_color(1 + area, 1 + maxarea, 'log'))
                self.painter.rect(qt.left, qt.top, qt.right, qt.bottom)
        else:
            for qt in done:
                self.painter.linestrip([qt.left, qt.right, qt.right, qt.left],
                                       [qt.top, qt.top, qt.bottom, qt.bottom],
                                       closed=True)

    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter.batch_draw()


data = geoplotlib.utils.read_csv('data/bus.csv')
geoplotlib.add_layer(QuadsLayer(data, cmap=None))
geoplotlib.set_smoothing(False)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()
예제 #16
0
        k_means.fit(np.vstack([x, y]).T)
        labels = k_means.labels_

        self.cmap = create_set_cmap(set(labels), 'hsv')
        for l in set(labels):
            self.painter.set_color(self.cmap[l])
            self.painter.convexhull(x[labels == l], y[labels == l])
            self.painter.points(x[labels == l], y[labels == l], 2)

    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        ui_manager.info(
            'Use left and right to increase/decrease the number of clusters. k = %d'
            % self.k)
        self.painter.batch_draw()

    def on_key_release(self, key, modifiers):
        if key == pyglet.window.key.LEFT:
            self.k = max(2, self.k - 1)
            return True
        elif key == pyglet.window.key.RIGHT:
            self.k = self.k + 1
            return True
        return False


data = geoplotlib.utils.read_csv('data/bus.csv')
geoplotlib.add_layer(KMeansLayer(data))
geoplotlib.set_smoothing(True)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()
예제 #17
0
        done = []
        while len(queue) > 0:
            qt = queue.pop()
            if qt.can_split(x, y):
                queue.extend(qt.split())
            else:
                done.append(qt)
        
        print len(queue), len(done)

        if self.cmap is not None:
            for qt in done:
                area = (qt.right - qt.left) * (qt.top - qt.bottom)
                self.painter.set_color(self.cmap.to_color(1 + area, 1 + maxarea, 'log'))
                self.painter.rect(qt.left, qt.top, qt.right, qt.bottom)
        else:
            for qt in done:
                self.painter.linestrip([qt.left, qt.right, qt.right, qt.left],
                                       [qt.top, qt.top, qt.bottom, qt.bottom], closed=True)
    
            
    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter.batch_draw()
  

data = geoplotlib.utils.read_csv('data/bus.csv')
geoplotlib.add_layer(QuadsLayer(data, cmap=None))
geoplotlib.set_smoothing(False)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()