本文整理匯總了Python中holoviews.Polygons方法的典型用法代碼示例。如果您正苦於以下問題:Python holoviews.Polygons方法的具體用法?Python holoviews.Polygons怎麽用?Python holoviews.Polygons使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類holoviews
的用法示例。
在下文中一共展示了holoviews.Polygons方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def setUp(self):
xs = [1, 2, 3]
ys = [2, 0, 7]
holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]]]
self.single_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}])
xs = [1, 2, 3, np.nan, 6, 7, 3]
ys = [2, 0, 7, np.nan, 7, 5, 2]
holes = [
[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]],
[]
]
self.multi_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}])
self.multi_poly_no_hole = Polygons([{'x': xs, 'y': ys}])
self.distinct_polys = Polygons([
{'x': xs, 'y': ys, 'holes': holes, 'value': 0},
{'x': [4, 6, 6], 'y': [0, 2, 1], 'value': 1}], vdims='value')
示例2: _process
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def _process(self, element, key=None):
try:
import cv2 as cv
except:
# HACK: Avoids error loading OpenCV the first time
# ImportError dlopen: cannot load any more object with static TLS
try:
import cv2 as cv
except ImportError:
raise ImportError('GrabCut algorithm requires openCV')
if isinstance(self.p.foreground, hv.Polygons):
rasterize_op = rasterize_polygon
else:
rasterize_op = rasterize.instance(aggregator=ds.any())
kwargs = {'dynamic': False, 'target': element}
fg_mask = rasterize_op(self.p.foreground, **kwargs)
bg_mask = rasterize_op(self.p.background, **kwargs)
fg_mask = fg_mask.dimension_values(2, flat=False)
bg_mask = bg_mask.dimension_values(2, flat=False)
if fg_mask[np.isfinite(fg_mask)].sum() == 0 or bg_mask[np.isfinite(bg_mask)].sum() == 0:
return element.clone([], vdims=['Foreground'], new_type=gv.Image,
crs=element.crs)
mask = np.where(fg_mask, 1, 2)
mask = np.where(bg_mask, 0, mask).copy()
bgdModel = np.zeros((1,65), np.float64)
fgdModel = np.zeros((1,65), np.float64)
if isinstance(element, hv.RGB):
img = np.dstack([element.dimension_values(d, flat=False)
for d in element.vdims])
else:
img = element.dimension_values(2, flat=False)
mask, _, _ = cv.grabCut(img, mask.astype('uint8'), None, bgdModel, fgdModel,
self.p.iterations, cv.GC_INIT_WITH_MASK)
fg_mask = np.where((mask==2)|(mask==0),0,1).astype('bool')
xs, ys = (element.dimension_values(d, expanded=False) for d in element.kdims)
return element.clone((xs, ys, fg_mask), vdims=['Foreground'], new_type=gv.Image,
crs=element.crs)
示例3: __init__
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def __init__(self, poly_data=[], **params):
super(SelectRegionPanel, self).__init__(**params)
self.boxes = gv.Polygons(poly_data).options(
fill_alpha=0.5, color='grey', line_color='white',
line_width=2, width=self.width, height=self.height
)
if not self.boxes:
self.boxes = self.boxes.options(global_extent=True)
self.box_stream = BoxEdit(source=self.boxes, num_objects=1)
示例4: test_bivariate_kde_contours_filled
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def test_bivariate_kde_contours_filled(self):
np.random.seed(1)
bivariate = Bivariate(np.random.rand(100, 2))
kde = bivariate_kde(bivariate, n_samples=100, x_range=(0, 1),
y_range=(0, 1), contours=True, filled=True, levels=10)
self.assertIsInstance(kde, Polygons)
self.assertEqual(len(kde.data), 10)
示例5: test_multi_poly_empty_holes
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def test_multi_poly_empty_holes(self):
poly = Polygons([])
self.assertFalse(poly.interface.has_holes(poly))
self.assertEqual(poly.interface.holes(poly), [])
示例6: test_single_poly_hole_validation
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def test_single_poly_hole_validation(self):
xs = [1, 2, 3]
ys = [2, 0, 7]
with self.assertRaises(DataError):
Polygons([{'x': xs, 'y': ys, 'holes': [[], []]}])
示例7: test_multi_poly_hole_validation
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def test_multi_poly_hole_validation(self):
xs = [1, 2, 3, np.nan, 6, 7, 3]
ys = [2, 0, 7, np.nan, 7, 5, 2]
with self.assertRaises(DataError):
Polygons([{'x': xs, 'y': ys, 'holes': [[]]}])
示例8: _box
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def _box(self, data):
if data is None:
return hv.Polygons([])
else:
diag = pd.DataFrame(data)
corners = []
for ir, r in diag.iterrows():
corners.append(
np.array([(r['x0'], r['y0']), (r['x0'], r['y1']),
(r['x1'], r['y1']), (r['x1'], r['y0'])]))
return hv.Polygons([{
('x', 'y'): cnr.squeeze()
} for cnr in corners])
示例9: roi_draw
# 需要導入模塊: import holoviews [as 別名]
# 或者: from holoviews import Polygons [as 別名]
def roi_draw(im):
h, w = im.sizes['height'], im.sizes['width']
opts_im = {'plot': {'height': h, 'width': w}, 'style': {'cmap': 'Viridis'}}
opts_box = {'style': {'fill_alpha': 0.3, 'line_color': 'white'}}
hv_im = regrid(hv.Image(im, kdims=['width', 'height'])).opts(**opts_im)
hv_box = hv.Polygons([]).opts(**opts_box)
str_box = BoxEdit(source=hv_box)
return hv_im * hv_box, str_box