Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _apply_dynspread(self, array):
img = tf.Image(array)
return tf.dynspread(img, max_px=self.p.max_px,
threshold=self.p.threshold,
how=self.p.how, shape=self.p.shape).data
def __init__(self, df, glyph, agg=reductions.count(),
transform_fn=identity, color_fn=tf.shade, spread_fn=tf.dynspread,
width_scale=1.0, height_scale=1.0):
self.df = df
self.glyph = glyph
self.agg = agg
self.transform_fn = transform_fn
self.color_fn = color_fn
self.spread_fn = spread_fn
self.width_scale = width_scale
self.height_scale = height_scale
def viewInteractiveImage(x_range, y_range, w, h, data_source):
cvs = cds.Canvas(
plot_width=w, plot_height=h, x_range=x_range, y_range=y_range
)
agg = cvs.points(
data_source,
self.x,
self.y,
getattr(cds, self.aggregate_fn)(self.aggregate_col),
)
img = tf.shade(
agg, cmap=self.color_palette, how=self.pixel_shade_type
)
if self.pixel_spread == "dynspread":
return tf.dynspread(
img,
threshold=self.pixel_density,
max_px=self.point_size,
shape=self.point_shape,
)
else:
return tf.spread(
img, px=self.point_size, shape=self.point_shape
)
elif edge_bundling == 'hammer':
warn('Hammer edge bundling is expensive for large graphs!\n'
'This may take a long time to compute!')
edges = bd.hammer_bundle(point_df, edge_df, weight='weight')
else:
raise ValueError('{} is not a recognised bundling method'.format(edge_bundling))
edge_img = tf.shade(canvas.line(edges, 'x', 'y', agg=ds.sum('weight')),
cmap=plt.get_cmap(edge_cmap), how=edge_how)
edge_img = tf.set_background(edge_img, background)
if show_points:
point_img = _datashade_points(points, None, labels, values, cmap, color_key,
color_key_cmap, None, width, height)
if px_size > 1:
point_img = tf.dynspread(point_img, threshold=0.5, max_px=px_size)
result = tf.stack(edge_img, point_img, how="over")
else:
result = edge_img
font_color = _select_font_color(background)
dpi = plt.rcParams['figure.dpi']
fig = plt.figure(figsize=(width / dpi, height / dpi))
ax = fig.add_subplot(111)
_embed_datashader_in_an_axis(result, ax)
ax.set(xticks=[], yticks=[])
ax.text(0.99,
0.01,
'UMAP: n_neighbors={}, min_dist={}'.format(umap_object.n_neighbors,
def _apply_spreading(self, array):
img = tf.Image(array)
return tf.dynspread(img, max_px=self.p.max_px,
threshold=self.p.threshold,
how=self.p.how, shape=self.p.shape).data