当前位置: 首页>>代码示例>>Python>>正文


Python core.BatchPainter类代码示例

本文整理汇总了Python中geoplotlib.core.BatchPainter的典型用法代码示例。如果您正苦于以下问题:Python BatchPainter类的具体用法?Python BatchPainter怎么用?Python BatchPainter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BatchPainter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ConvexHullLayer

class ConvexHullLayer(BaseLayer):

    def __init__(self, data, col, fill=True, point_size=4):
        """
        Convex hull for a set of points

        :param data: points
        :param col: color
        :param fill: whether to fill the convexhull polygon or not
        :param point_size: size of the points on the convexhull. Points are not rendered if None
        """
        self.data = data
        self.col = col
        self.fill = fill
        self.point_size=point_size


    def invalidate(self, proj):
        self.painter = BatchPainter()
        self.painter.set_color(self.col)
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
        if len(x) >= 3:
            self.painter.convexhull(x, y, self.fill)
        else:
            self.painter.linestrip(x, y)

        if self.point_size > 0:
            self.painter.points(x, y, self.point_size)


    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter.batch_draw()
开发者ID:h0pbeat,项目名称:geoplotlib,代码行数:32,代码来源:layers.py

示例2: GraphLayer

class GraphLayer(BaseLayer):

    def __init__(self, data, src_lat, src_lon, dest_lat, dest_lon, linewidth=1, alpha=220, color='hot'):
        """Create a graph drawing a line between each pair of (src_lat, src_lon) and (dest_lat, dest_lon)

        :param data: data access object
        :param src_lat: field name of source latitude
        :param src_lon: field name of source longitude
        :param dest_lat: field name of destination latitude
        :param dest_lon: field name of destination longitude
        :param linewidth: line width
        :param alpha: color alpha
        :param color: color or colormap
        """
        self.data = data
        self.src_lon = src_lon
        self.src_lat = src_lat
        self.dest_lon = dest_lon
        self.dest_lat = dest_lat

        self.linewidth = linewidth
        alpha = alpha
        self.color = color
        if type(self.color) == str:
            self.cmap = colors.ColorMap(self.color, alpha)


    def invalidate(self, proj):
        self.painter = BatchPainter()
        x0, y0 = proj.lonlat_to_screen(self.data[self.src_lon], self.data[self.src_lat])
        x1, y1 = proj.lonlat_to_screen(self.data[self.dest_lon], self.data[self.dest_lat])

        if type(self.color) == list:
            self.painter.set_color(self.color)
            self.painter.lines(x0, y0, x1, y1, width=self.linewidth)
        else:
            manhattan = np.abs(x0-x1) + np.abs(y0-y1)
            vmax = manhattan.max()
            distances = np.logspace(0, log10(manhattan.max()), 20)
            for i in range(len(distances)-1, 1, -1):
                mask = (manhattan > distances[i-1]) & (manhattan <= distances[i])
                self.painter.set_color(self.cmap.to_color(distances[i], vmax, 'log'))
                self.painter.lines(x0[mask], y0[mask], x1[mask], y1[mask], width=self.linewidth)


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


    def bbox(self):
        return BoundingBox.from_points(lons=np.hstack([self.data[self.src_lon], self.data[self.dest_lon]]),
                                       lats=np.hstack([self.data[self.src_lat], self.data[self.dest_lat]]))
开发者ID:h0pbeat,项目名称:geoplotlib,代码行数:52,代码来源:layers.py

示例3: KMeansLayer

class KMeansLayer(BaseLayer):

    def __init__(self, data):
        self.data = data


    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])

        k_means = KMeans()
        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):
            try:
                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)
            except Exception:
                print '=============',l,'=============='

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


    def on_key_release(self, key, modifiers):
        return False
开发者ID:Sleeperqp,项目名称:predict_destination,代码行数:29,代码来源:s_kmeans.py

示例4: KMeansLayer

class KMeansLayer(BaseLayer):

    def __init__(self, data):
        self.data = data
        self.k = 2


    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])

        k_means = KMeans(n_clusters=self.k)
        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
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:35,代码来源:kmeans.py

示例5: MarkersLayer

class MarkersLayer(BaseLayer):

    def __init__(self, data, marker, f_tooltip=None, marker_preferred_size=32):
        """
        Draw markers

        :param data: data access object
        :param marker: full filename of the marker image
        :param f_tooltip: function to generate a tooltip on mouseover
        :param marker_preferred_size: size in pixel for the marker images
        """
        self.data = data
        self.f_tooltip = f_tooltip
        self.marker_preferred_size = float(marker_preferred_size)
        self.marker = pyglet.image.load(marker)
        self.marker.anchor_x = self.marker.width / 2
        self.marker.anchor_y = self.marker.height / 2
        self.scale = self.marker_preferred_size / max(self.marker.width, self.marker.height)

        self.hotspots = HotspotManager()


    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])

        if self.f_tooltip:
            for i in range(0, len(x)):
                record = {k: self.data[k][i] for k in self.data.keys()}
                self.hotspots.add_rect(x[i] - self.marker_preferred_size/2,
                                       y[i] - self.marker_preferred_size/2,
                                       self.marker_preferred_size,
                                       self.marker_preferred_size,
                                       self.f_tooltip(record))

        self.painter.sprites(self.marker, x, y, self.scale)


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

        picked = self.hotspots.pick(mouse_x, mouse_y)
        if picked:
            ui_manager.tooltip(picked)


    def bbox(self):
        return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
开发者ID:h0pbeat,项目名称:geoplotlib,代码行数:48,代码来源:layers.py

示例6: invalidate

    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
        self.data['_xbin'] = (x / self.binsize).astype(int)
        self.data['_ybin'] = (y / self.binsize).astype(int)
        uniquevalues = set([tuple(row) for row in np.vstack([self.data['_xbin'],self.data['_ybin']]).T])
        results = {(v1,v2): self.f_group(self.data.where((self.data['_xbin'] == v1) & (self.data['_ybin'] == v2))) \
                   for v1, v2 in uniquevalues}
        del self.data['_xbin']
        del self.data['_ybin']

        self.hotspot = HotspotManager()

        if self.scalemax:
            vmax = self.scalemax
        else:
            vmax = max(results.values()) if len(results) > 0 else 0

        if vmax >= 1:
            for (ix, iy), value in results.items():
                if value > self.scalemin:
                    self.painter.set_color(self.cmap.to_color(value, vmax, self.colorscale))
                    l = self.binsize
                    rx = ix * self.binsize
                    ry = iy * self.binsize

                    self.painter.rect(rx, ry, rx+l, ry+l)
                    if self.show_tooltip:
                        self.hotspot.add_rect(rx, ry, l, l, 'Value: %d' % value)
开发者ID:h0pbeat,项目名称:geoplotlib,代码行数:29,代码来源:layers.py

示例7: invalidate

    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
        
        w = x.max() - x.min()
        h = y.max() - y.min()
        w = np.ceil(w / 2) * 2
        h = np.ceil(h / 2) * 2
        l = max(w, h)
        
        root = QuadTree(x.min(), x.min() + l, y.min() + l, y.min())
        maxarea = (root.right - root.left) * (root.top - root.bottom)
        queue = [root]
        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)
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:32,代码来源:quadtree.py

示例8: invalidate

 def invalidate(self, proj):
     self.painter = BatchPainter()
     x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
     self.painter.set_color(self.color)
     self.painter.labels(x, y, self.data[self.label_column], 
                                 font_name=self.font_name,
                                 font_size=self.font_size,
                                 anchor_x=self.anchor_x, 
                                 anchor_y=self.anchor_y)
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:9,代码来源:layers.py

示例9: TrailsLayer

class TrailsLayer(BaseLayer):

    def __init__(self):
        self.data = read_csv('data/taxi.csv')
        self.cmap = colorbrewer(self.data['taxi_id'], alpha=220)
        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 + 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)
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:30,代码来源:taxi.py

示例10: invalidate

    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])

        k_means = KMeans(n_clusters=self.k)
        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)
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:13,代码来源:kmeans.py

示例11: draw

    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))
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:13,代码来源:follow_camera.py

示例12: invalidate

 def invalidate(self, proj):
     self.painter = BatchPainter()
     x0, y0 = proj.lonlat_to_screen(self.data[self.src_lon], self.data[self.src_lat])
     x1, y1 = proj.lonlat_to_screen(self.data[self.dest_lon], self.data[self.dest_lat])
     manhattan = np.abs(x0-x1) + np.abs(y0-y1)
     vmax = manhattan.max()
     distances = np.logspace(0, log10(manhattan.max()), 20)
     for i in range(len(distances)-1, 1, -1):
         mask = (manhattan > distances[i-1]) & (manhattan <= distances[i])
         if type(self.color) == list:
             self.painter.set_color(self.color)
         else:
             self.painter.set_color(self.cmap.to_color(distances[i], vmax, 'log'))
         self.painter.lines(x0[mask], y0[mask], x1[mask], y1[mask], width=self.linewidth)
开发者ID:MichaMucha,项目名称:geoplotlib,代码行数:14,代码来源:layers.py

示例13: GridLayer

class GridLayer(BaseLayer):

    def __init__(self, lon_edges, lat_edges, values, cmap, alpha=255, vmin=None, vmax=None):
        self.lon_edges = lon_edges
        self.lat_edges = lat_edges
        self.values = values
        self.cmap = colors.ColorMap(cmap, alpha=alpha)

        if vmin:
            self.vmin = vmin
        else:
            self.vmin = 0

        if vmax:
            self.vmax = vmax
        else:
            self.vmax = self.values.max()


    def invalidate(self, proj):
        self.painter = BatchPainter()
        xv, yv = proj.lonlat_to_screen(self.lon_edges, self.lat_edges)

        rects = []
        cols = []
        for ix in range(len(xv)-1):
            for iy in range(len(yv)-1):
                d = self.values[iy, ix]
                if d > self.vmin:
                    rects.append((xv[ix], yv[iy], xv[ix+1], yv[iy+1]))
                    cols.append(self.cmap.to_color(d, self.vmax, 'lin'))

        self.painter.batch_rects(rects, cols)


    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter.batch_draw()
开发者ID:h0pbeat,项目名称:geoplotlib,代码行数:37,代码来源:layers.py

示例14: QuadsLayer

class QuadsLayer(BaseLayer):

    def __init__(self, data, cmap='hot_r'):
        self.data = data
        if cmap is not None:
            self.cmap = geoplotlib.colors.ColorMap(cmap, alpha=196)
        else:
            self.cmap = None
            

    def invalidate(self, proj):
        self.painter = BatchPainter()
        x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
        
        w = x.max() - x.min()
        h = y.max() - y.min()
        w = np.ceil(w / 2) * 2
        h = np.ceil(h / 2) * 2
        l = max(w, h)
        
        root = QuadTree(x.min(), x.min() + l, y.min() + l, y.min())
        maxarea = (root.right - root.left) * (root.top - root.bottom)
        queue = [root]
        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()
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:46,代码来源:quadtree.py

示例15: draw

    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))
开发者ID:JaredChung,项目名称:geoplotlib,代码行数:17,代码来源:taxi.py


注:本文中的geoplotlib.core.BatchPainter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。