Skip to content

Commit

Permalink
delay projection comparison to optimize geoviews (#5152)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt committed Dec 6, 2021
1 parent e53b9cb commit 2c405db
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion holoviews/plotting/bokeh/element.py
Expand Up @@ -693,7 +693,8 @@ def _axis_properties(self, axis, key, plot, dimension=None,
elif axis == 'y':
axis_obj = plot.yaxis[0]

if self.geographic and self.projection == 'mercator':
if (self.geographic and isinstance(self.projection, str)
and self.projection == 'mercator'):
dimension = 'lon' if axis == 'x' else 'lat'
axis_props['ticker'] = MercatorTicker(dimension=dimension)
axis_props['formatter'] = MercatorTickFormatter(dimension=dimension)
Expand Down
10 changes: 5 additions & 5 deletions holoviews/plotting/mpl/element.py
Expand Up @@ -171,7 +171,7 @@ def _finalize_axis(self, key, element=None, title=None, dimensions=None, ranges=
if self.logy:
axis.set_yscale('log')

if not self.projection == '3d':
if not isinstance(self.projection, str) and self.projection == '3d':
self._set_axis_position(axis, 'x', self.xaxis)
self._set_axis_position(axis, 'y', self.yaxis)

Expand Down Expand Up @@ -207,7 +207,7 @@ def _finalize_ticks(self, axis, dimensions, xticks, yticks, zticks):
self._set_axis_formatter(axis.xaxis, xdim, self.xformatter)
if ydim:
self._set_axis_formatter(axis.yaxis, ydim, self.yformatter)
if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
zdim = dimensions[2] if ndims > 2 else None
if zdim or self.zformatter is not None:
self._set_axis_formatter(axis.zaxis, zdim, self.zformatter)
Expand All @@ -220,7 +220,7 @@ def _finalize_ticks(self, axis, dimensions, xticks, yticks, zticks):
self._set_axis_ticks(axis.yaxis, yticks, log=self.logy,
rotation=self.yrotation)

if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
zticks = zticks if zticks else self.zticks
self._set_axis_ticks(axis.zaxis, zticks, log=self.logz,
rotation=self.zrotation)
Expand Down Expand Up @@ -292,7 +292,7 @@ def _set_aspect(self, axes, aspect):
"""
Set the aspect on the axes based on the aspect setting.
"""
if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
return

if ((isinstance(aspect, str) and aspect != 'square') or
Expand Down Expand Up @@ -324,7 +324,7 @@ def _set_axis_limits(self, axis, view, subplots, ranges):
coords = [coord if np.isreal(coord) or isinstance(coord, np.datetime64) else np.NaN for coord in extents]
coords = [date2num(util.dt64_to_dt(c)) if isinstance(c, np.datetime64) else c
for c in coords]
if self.projection == '3d' or len(extents) == 6:
if isinstance(self.projection, str) and self.projection == '3d' or len(extents) == 6:
l, b, zmin, r, t, zmax = coords
if self.invert_zaxis or any(p.invert_zaxis for p in subplots):
zmin, zmax = zmax, zmin
Expand Down
29 changes: 18 additions & 11 deletions holoviews/plotting/plot.py
Expand Up @@ -1320,7 +1320,7 @@ def _get_range_extents(self, element, ranges, range_type, xdim, ydim, zdim):
ndims = len(dims)
xdim = xdim or (dims[0] if ndims else None)
ydim = ydim or (dims[1] if ndims > 1 else None)
if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
zdim = zdim or (dims[2] if ndims > 2 else None)
else:
zdim = None
Expand Down Expand Up @@ -1364,7 +1364,7 @@ def _get_range_extents(self, element, ranges, range_type, xdim, ydim, zdim):
elif ydim is None:
y0, y1 = np.NaN, np.NaN

if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
if range_type == 'soft':
z0, z1 = zsrange
elif range_type == 'data':
Expand Down Expand Up @@ -1407,14 +1407,17 @@ def get_extents(self, element, ranges, range_type='combined', xdim=None, ydim=No
This allows Overlay plots to obtain each range and combine them
appropriately for all the objects in the overlay.
"""
num = 6 if self.projection == '3d' else 4
num = 6 if (isinstance(self.projection, str) and self.projection == '3d') else 4
if self.apply_extents and range_type in ('combined', 'extents'):
norm_opts = self.lookup_options(element, 'norm').options
if norm_opts.get('framewise', False) or self.dynamic:
extents = element.extents
else:
extent_list = self.hmap.traverse(lambda x: x.extents, [Element])
extents = util.max_extents(extent_list, self.projection == '3d')
extents = util.max_extents(
extent_list,
isinstance(self.projection, str) and self.projection == '3d'
)
else:
extents = (np.NaN,) * num

Expand All @@ -1427,7 +1430,10 @@ def get_extents(self, element, ranges, range_type='combined', xdim=None, ydim=No
range_extents = (np.NaN,) * num

if getattr(self, 'shared_axes', False) and self.subplot:
combined = util.max_extents([range_extents, extents], self.projection == '3d')
combined = util.max_extents(
[range_extents, extents],
isinstance(self.projection, str) and self.projection == '3d'
)
else:
max_extent = []
for l1, l2 in zip(range_extents, extents):
Expand All @@ -1437,7 +1443,7 @@ def get_extents(self, element, ranges, range_type='combined', xdim=None, ydim=No
max_extent.append(l1)
combined = tuple(max_extent)

if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
x0, y0, z0, x1, y1, z1 = combined
else:
x0, y0, x1, y1 = combined
Expand All @@ -1460,7 +1466,7 @@ def get_extents(self, element, ranges, range_type='combined', xdim=None, ydim=No
if stream not in self._trigger and (self.xlim or self.ylim):
self._trigger.append(stream)

if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
z0, z1 = util.dimension_range(z0, z1, self.zlim, (None, None))
return (x0, y0, z0, x1, y1, z1)
return (x0, y0, x1, y1)
Expand All @@ -1480,7 +1486,8 @@ def _get_axis_labels(self, dimensions, xlabel=None, ylabel=None, zlabel=None):

if getattr(self, 'zlabel', None) is not None:
zlabel = self.zlabel
elif self.projection == '3d' and len(dimensions) >= 3 and zlabel is None:
elif (isinstance(self.projection, str) and self.projection == '3d'
and len(dimensions) >= 3 and zlabel is None):
zlabel = dim_axis_label(dimensions[2]) if dimensions[2] else ''
return xlabel, ylabel, zlabel

Expand Down Expand Up @@ -1800,7 +1807,7 @@ def _get_subplot_extents(self, overlay, ranges, range_type):

def get_extents(self, overlay, ranges, range_type='combined'):
subplot_extents = self._get_subplot_extents(overlay, ranges, range_type)
zrange = self.projection == '3d'
zrange = isinstance(self.projection, str) and self.projection == '3d'
extents = {k: util.max_extents(rs, zrange) for k, rs in subplot_extents.items()}
if range_type != 'combined':
return extents[range_type]
Expand Down Expand Up @@ -1834,15 +1841,15 @@ def get_extents(self, overlay, ranges, range_type='combined'):

# Combine with Element.extents
combined = util.max_extents([padded, extents['extents']], zrange)
if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
x0, y0, z0, x1, y1, z1 = combined
else:
x0, y0, x1, y1 = combined

# Apply xlim, ylim, zlim plot option
x0, x1 = util.dimension_range(x0, x1, self.xlim, (None, None))
y0, y1 = util.dimension_range(y0, y1, self.ylim, (None, None))
if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
z0, z1 = util.dimension_range(z0, z1, getattr(self, 'zlim', (None, None)), (None, None))
return (x0, y0, z0, x1, y1, z1)
return (x0, y0, x1, y1)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/plotly/element.py
Expand Up @@ -525,7 +525,7 @@ def init_layout(self, key, element, ranges, is_geo=False):
mapbox["zoom"] = min(max_x_zoom, max_y_zoom)
layout["mapbox"] = mapbox

if self.projection == '3d':
if isinstance(self.projection, str) and self.projection == '3d':
scene = dict(xaxis=xaxis, yaxis=yaxis)
if zdim:
zrange = [z1, z0] if self.invert_zaxis else [z0, z1]
Expand Down

0 comments on commit 2c405db

Please sign in to comment.