@@ -345,6 +345,38 @@ def bounds_are_done(self):
345
345
(p in self .pending_points or p in self ._stack ) for p in self ._bounds_points
346
346
)
347
347
348
+ def data_on_grid (self , n = None ):
349
+ """Get the interpolated data on a grid.
350
+
351
+ Parameters
352
+ ----------
353
+ n : int, optional
354
+ Number of points in x and y. If None (default) this number is
355
+ evaluated by looking at the size of the smallest triangle.
356
+
357
+ Returns
358
+ -------
359
+ xs : 1D numpy.ndarray, optional
360
+ ys : 1D numpy.ndarray, optional
361
+ data_on_grid : 2D numpy.ndarray
362
+ """
363
+ ip = self .ip ()
364
+ if n is None :
365
+ # Calculate how many grid points are needed.
366
+ # factor from A=√3/4 * a² (equilateral triangle)
367
+ n = int (0.658 / sqrt (areas (ip ).min ()))
368
+ n = max (n , 10 )
369
+
370
+ # The bounds of the linspace should be (-0.5, 0.5) but because of
371
+ # numerical precision problems it could (for example) be
372
+ # (-0.5000000000000001, 0.49999999999999983), then any point at exact
373
+ # boundary would be outside of the domain. See #181.
374
+ eps = 1e-13
375
+ xs = ys = np .linspace (- 0.5 + eps , 0.5 - eps , n )
376
+ zs = ip (xs [:, None ], ys [None , :] * self .aspect_ratio ).squeeze ()
377
+ xs , ys = self ._unscale (np .vstack ([xs , ys ]).T ).T
378
+ return xs , ys , zs
379
+
348
380
def _data_in_bounds (self ):
349
381
if self .data :
350
382
points = np .array (list (self .data .keys ()))
@@ -542,20 +574,7 @@ def plot(self, n=None, tri_alpha=0):
542
574
543
575
if len (self .data ) >= 4 :
544
576
ip = self .ip ()
545
-
546
- if n is None :
547
- # Calculate how many grid points are needed.
548
- # factor from A=√3/4 * a² (equilateral triangle)
549
- n = int (0.658 / sqrt (areas (ip ).min ()))
550
- n = max (n , 10 )
551
-
552
- # The bounds of the linspace should be (-0.5, 0.5) but because of
553
- # numerical precision problems it could (for example) be
554
- # (-0.5000000000000001, 0.49999999999999983), then any point at exact
555
- # boundary would be outside of the domain. See #181.
556
- eps = 1e-13
557
- x = y = np .linspace (- 0.5 + eps , 0.5 - eps , n )
558
- z = ip (x [:, None ], y [None , :] * self .aspect_ratio ).squeeze ()
577
+ x , y , z = self .data_on_grid (n )
559
578
560
579
if self .vdim > 1 :
561
580
ims = {
0 commit comments