本文整理汇总了Python中geoplotlib.core.BatchPainter.lines方法的典型用法代码示例。如果您正苦于以下问题:Python BatchPainter.lines方法的具体用法?Python BatchPainter.lines怎么用?Python BatchPainter.lines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geoplotlib.core.BatchPainter
的用法示例。
在下文中一共展示了BatchPainter.lines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import lines [as 别名]
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]]))
示例2: DelaunayLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import lines [as 别名]
class DelaunayLayer(BaseLayer):
def __init__(self, data, line_color=None, line_width=2, cmap=None, max_lenght=100):
"""
Draw a delaunay triangulation of the points
:param data: data access object
:param line_color: line color
:param line_width: line width
:param cmap: color map
:param max_lenght: scaling constant for coloring the edges
"""
self.data = data
if cmap is None and line_color is None:
raise Exception('need either cmap or line_color')
if cmap is not None:
cmap = colors.ColorMap(cmap, alpha=196)
self.cmap = cmap
self.line_color = line_color
self.line_width = line_width
self.max_lenght = max_lenght
@staticmethod
def _get_area(p):
x1, y1, x2, y2, x3, y3 = p
return 0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))
def invalidate(self, proj):
try:
from scipy.spatial.qhull import Delaunay
except ImportError:
print('DelaunayLayer needs scipy >= 0.12')
raise
self.painter = BatchPainter()
x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
points = list(set(zip(x,y)))
dela = Delaunay(points)
edges = set()
for tria in dela.vertices:
edges.add((tria[0], tria[1]))
edges.add((tria[1], tria[2]))
edges.add((tria[2], tria[0]))
allx0 = []
ally0 = []
allx1 = []
ally1 = []
colors = []
for a, b in edges:
x0, y0 = dela.points[a]
x1, y1 = dela.points[b]
allx0.append(x0)
ally0.append(y0)
allx1.append(x1)
ally1.append(y1)
if self.line_color:
colors.append(self.line_color)
colors.append(self.line_color)
elif self.cmap:
l = math.sqrt((x0 - x1)**2+(y0 - y1)**2)
c = self.cmap.to_color(l, self.max_lenght, 'log')
colors.append(c)
colors.append(c)
self.painter.lines(allx0, ally0, allx1, ally1, colors, width=self.line_width)
def draw(self, proj, mouse_x, mouse_y, ui_manager):
self.painter.batch_draw()
def bbox(self):
return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])