本文整理汇总了Python中geoplotlib.core.BatchPainter.convexhull方法的典型用法代码示例。如果您正苦于以下问题:Python BatchPainter.convexhull方法的具体用法?Python BatchPainter.convexhull怎么用?Python BatchPainter.convexhull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geoplotlib.core.BatchPainter
的用法示例。
在下文中一共展示了BatchPainter.convexhull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KMeansLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import convexhull [as 别名]
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
示例2: ConvexHullLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import convexhull [as 别名]
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()
示例3: KMeansLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import convexhull [as 别名]
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