Browse code

2D: use hv.TriMesh instead of hv.Contours

Bas Nijholt authored on 08/12/2017 23:51:42
Showing 1 changed files
... ...
@@ -328,15 +328,14 @@ class Learner2D(BaseLearner):
328 328
 
329 329
             x = y = np.linspace(-0.5, 0.5, n)
330 330
             z = ip(x[:, None], y[None, :]).squeeze()
331
-            plot = hv.Image(np.rot90(z), bounds=lbrt)
332
-
333
-            if tri_alpha:
334
-                tri_points = self.unscale(ip.tri.points[ip.tri.vertices])
335
-                contours = hv.Contours([p for p in tri_points])
336
-                contours = contours.opts(style=dict(alpha=tri_alpha))
337 331
 
332
+            image = hv.Image(np.rot90(z), bounds=lbrt).opts(style=dict(cmap='viridis'))
333
+            tris = hv.TriMesh((ip.tri.simplices, self.unscale(ip.tri.points)))
334
+            opts = dict(node_alpha=0, lw=0.1, edge_fill_color='w',
335
+                        edge_line_alpha=tri_alpha)
336
+            tris = tris.opts(style=opts)
337
+            plot = image * (tris if tri_alpha else hv.TriMesh([]))
338 338
         else:
339
-            plot = hv.Image([], bounds=lbrt)
340
-            contours = hv.Contours([])
339
+            plot = hv.Image([]) * hv.TriMesh([])
341 340
 
342
-        return plot * contours if tri_alpha else plot
341
+        return plot