Skip to content

Commit

Permalink
Fixed plotting of QuadMesh with nan coordinates (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed May 21, 2018
1 parent 0cd9395 commit 18ca8a4
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def get_data(self, element, ranges, style):
if self.static_source:
return {}, mapping, style

x, y = dimension_sanitizer(x.name), dimension_sanitizer(y.name)

zdata = element.dimension_values(z, flat=False)
if irregular:
dims = element.kdims
Expand All @@ -156,11 +158,24 @@ def get_data(self, element, ranges, style):
X, Y = colormesh(X, Y)
zvals = zdata.T.flatten() if self.invert_axes else zdata.flatten()
XS, YS = [], []
for x, y, zval in zip(X, Y, zvals):
if np.isfinite(zval):
XS.append(list(x[:-1]))
YS.append(list(y[:-1]))
data = {'xs': XS, 'ys': YS, z.name: zvals[np.isfinite(zvals)]}
mask = []
xc, yc = [], []
for xs, ys, zval in zip(X, Y, zvals):
xs, ys = xs[:-1], ys[:-1]
if np.isfinite(zval) and all(np.isfinite(c) for c in xs) and all(np.isfinite(c) for c in ys):
XS.append(list(xs))
YS.append(list(ys))
mask.append(True)
if 'hover' in self.handles:
xc.append(xs.mean())
yc.append(ys.mean())
else:
mask.append(False)

data = {'xs': XS, 'ys': YS, z.name: zvals[np.array(mask)]}
if 'hover' in self.handles:
data[x] = np.array(xc)
data[y] = np.array(yc)
else:
xc, yc = (element.interface.coords(element, x, edges=True),
element.interface.coords(element, y, edges=True))
Expand All @@ -170,8 +185,8 @@ def get_data(self, element, ranges, style):
data = {'left': x0, 'right': x1, dimension_sanitizer(z.name): zvals,
'bottom': y0, 'top': y1}
if 'hover' in self.handles and not self.static_source:
data[dimension_sanitizer(x.name)] = element.dimension_values(x)
data[dimension_sanitizer(y.name)] = element.dimension_values(y)
data[x] = element.dimension_values(x)
data[y] = element.dimension_values(y)
return data, mapping, style


Expand Down

0 comments on commit 18ca8a4

Please sign in to comment.