From 9d74f7ecef1ffc56e4beb19fc69b809e597e9162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Wed, 6 Sep 2023 09:37:59 +0200 Subject: [PATCH] Try/except get_extents without dimension and add kwargs to all get_extents (#5872) --- holoviews/plotting/bokeh/element.py | 10 ++++++---- holoviews/plotting/mpl/chart.py | 4 ++-- holoviews/plotting/mpl/heatmap.py | 2 +- holoviews/plotting/mpl/raster.py | 4 ++-- holoviews/plotting/mpl/sankey.py | 2 +- holoviews/plotting/plot.py | 2 +- holoviews/plotting/plotly/chart.py | 2 +- holoviews/plotting/plotly/tiles.py | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 633e6f690e..079311b93e 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -420,9 +420,11 @@ def _axis_props(self, plots, subplots, element, ranges, pos, *, dim=None, axis_label = str(dim) specs = ((dim.name, dim.label, dim.unit),) else: - if isinstance(self, OverlayPlot): + try: l, b, r, t = self.get_extents(range_el, ranges, dimension=dim) - else: + except TypeError: + # Backward compatibility for e.g. GeoViews=<1.10.1 since dimension + # is a newly added keyword argument in HoloViews 1.17 l, b, r, t = self.get_extents(range_el, ranges) if self.invert_axes: l, b, r, t = b, l, t, r @@ -983,9 +985,9 @@ def _update_main_ranges(self, element, x_range, y_range, ranges): range_dim = None try: l, b, r, t = self.get_extents(element, ranges, dimension=range_dim) - except Exception: + except TypeError: # Backward compatibility for e.g. GeoViews=<1.10.1 since dimension - # is a newly added keyword argument + # is a newly added keyword argument in HoloViews 1.17 l, b, r, t = self.get_extents(element, ranges) if self.invert_axes: l, b, r, t = b, l, t, r diff --git a/holoviews/plotting/mpl/chart.py b/holoviews/plotting/mpl/chart.py index 5e9b371cc8..6f9b2f2931 100644 --- a/holoviews/plotting/mpl/chart.py +++ b/holoviews/plotting/mpl/chart.py @@ -276,7 +276,7 @@ def get_data(self, element, ranges, style): pos_error = element.dimension_values(pos_idx) return (xs, mean-neg_error, mean+pos_error), style, {} - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): return ChartPlot.get_extents(self, element, ranges, range_type) @@ -390,7 +390,7 @@ def _compute_ticks(self, element, edges, widths, lims): labels = [dim.pprint_value(v) for v in xvals] return [xvals, labels] - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): ydim = element.get_dimension(1) s0, s1 = ranges[ydim.name]['soft'] s0 = min(s0, 0) if isfinite(s0) else 0 diff --git a/holoviews/plotting/mpl/heatmap.py b/holoviews/plotting/mpl/heatmap.py index bd4d12d31b..2cb853594f 100644 --- a/holoviews/plotting/mpl/heatmap.py +++ b/holoviews/plotting/mpl/heatmap.py @@ -298,7 +298,7 @@ def _get_ticks(ticks, ticker): return ticks - def get_extents(self, view, ranges, range_type='combined'): + def get_extents(self, view, ranges, range_type='combined', **kwargs): if range_type == 'hard': return (np.nan,)*4 return (0, 0, np.pi*2, self.max_radius+self.radius_outer) diff --git a/holoviews/plotting/mpl/raster.py b/holoviews/plotting/mpl/raster.py index fce172c55f..3d524241e5 100644 --- a/holoviews/plotting/mpl/raster.py +++ b/holoviews/plotting/mpl/raster.py @@ -37,7 +37,7 @@ class RasterBasePlot(ElementPlot): _plot_methods = dict(single='imshow') - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): extents = super().get_extents(element, ranges, range_type) if self.situate_axes or range_type not in ('combined', 'data'): return extents @@ -294,7 +294,7 @@ def __init__(self, layout, keys=None, dimensions=None, create_axes=False, ranges def _finalize_artist(self, key): pass - def get_extents(self, view, ranges, range_type='combined'): + def get_extents(self, view, ranges, range_type='combined', **kwargs): if range_type == 'hard': return (np.nan,)*4 width, height, _, _, _, _ = self.border_extents diff --git a/holoviews/plotting/mpl/sankey.py b/holoviews/plotting/mpl/sankey.py index 875d2d7c41..7efa97b147 100644 --- a/holoviews/plotting/mpl/sankey.py +++ b/holoviews/plotting/mpl/sankey.py @@ -47,7 +47,7 @@ class SankeyPlot(GraphPlot): style_opts = GraphPlot.style_opts + ['label_text_font_size'] - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): """ A Chord plot is always drawn on a unit circle. """ diff --git a/holoviews/plotting/plot.py b/holoviews/plotting/plot.py index 29d60f51b0..d4c91e9a16 100644 --- a/holoviews/plotting/plot.py +++ b/holoviews/plotting/plot.py @@ -1407,7 +1407,7 @@ def _get_range_extents(self, element, ranges, range_type, xdim, ydim, zdim): return (x0, y0, x1, y1) - def get_extents(self, element, ranges, range_type='combined', dimension=None, xdim=None, ydim=None, zdim=None): + def get_extents(self, element, ranges, range_type='combined', dimension=None, xdim=None, ydim=None, zdim=None, **kwargs): """ Gets the extents for the axes from the current Element. The globally computed ranges can optionally override the extents. diff --git a/holoviews/plotting/plotly/chart.py b/holoviews/plotting/plotly/chart.py index e9ec476709..8f65bf3049 100644 --- a/holoviews/plotting/plotly/chart.py +++ b/holoviews/plotting/plotly/chart.py @@ -214,7 +214,7 @@ def _get_axis_dims(self, element): xdims = element.kdims[0] return (xdims, element.vdims[0]) - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): x0, y0, x1, y1 = BarsMixin.get_extents(self, element, ranges, range_type) if range_type not in ('data', 'combined'): return x0, y0, x1, y1 diff --git a/holoviews/plotting/plotly/tiles.py b/holoviews/plotting/plotly/tiles.py index 0cbf1a700e..6ecede77dd 100644 --- a/holoviews/plotting/plotly/tiles.py +++ b/holoviews/plotting/plotly/tiles.py @@ -53,7 +53,7 @@ def graph_options(self, element, ranges, style, **kwargs): return opts - def get_extents(self, element, ranges, range_type='combined'): + def get_extents(self, element, ranges, range_type='combined', **kwargs): extents = super().get_extents(element, ranges, range_type) if (not self.overlaid and all(e is None or not np.isfinite(e) for e in extents) and range_type in ('combined', 'data')):