Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed plotting of QuadMesh with nan coordinates #2691

Merged
merged 2 commits into from
May 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am misunderstanding, but why can't you just compute the mask and apply that to xs and ys instead of defining XS and YS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XS and YS are lists of arrays and not arrays themselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be perfectly accurate they are lists of lists since the overhead for serializing and deserializing a bunch of tiny arrays is much larger than any benefit gained.

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