From 237de09122f3fe45657fbac251b64bd5534adc98 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 12 Sep 2019 19:49:57 +0200 Subject: [PATCH] Fix Grid level alignment (#3957) --- examples/user_guide/Plotting_with_Bokeh.ipynb | 44 +++++++++++++++++++ holoviews/plotting/bokeh/element.py | 4 ++ holoviews/plotting/bokeh/plot.py | 2 + 3 files changed, 50 insertions(+) diff --git a/examples/user_guide/Plotting_with_Bokeh.ipynb b/examples/user_guide/Plotting_with_Bokeh.ipynb index 5f936c2a42..82a7f5245e 100644 --- a/examples/user_guide/Plotting_with_Bokeh.ipynb +++ b/examples/user_guide/Plotting_with_Bokeh.ipynb @@ -282,6 +282,50 @@ "img.opts(data_aspect=0.5, responsive=True, title='scale both')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Alignment\n", + "\n", + "The aligment of a plot in a row or column can be controlled using ``align`` option. It controls both the vertical alignment in a row and the horizontal alignment in a column and can be set to one of `'start'`, `'center'` or `'end'` (where `'start'` is the default)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Vertical" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "points = hv.Points(data).opts(axiswise=True)\n", + "img = hv.Image((xs, ys, xs[:, np.newaxis]*np.sin(ys*4)))\n", + "\n", + "img + points.opts(height=200, align='end')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Horizontal" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "(img.opts(axiswise=True, width=200, align='center') + points).cols(1)" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index d0d099f1c6..4adb66bc82 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -51,6 +51,9 @@ class ElementPlot(BokehPlot, GenericElementPlot): both 'pan' and 'box_zoom' are drag tools, so if both are listed only the last one will be active.""") + align = param.ObjectSelector(default=None, objects=['start', 'center', 'end'], doc=""" + Alignment (vertical or horizontal) of the plot in a layout.""") + border = param.Number(default=10, doc=""" Minimum border around plot.""") @@ -503,6 +506,7 @@ def _plot_properties(self, key, element): self.callbacks.append(PlotSizeCallback(self, [stream], None)) plot_props = { + 'align': self.align, 'margin': self.margin, 'max_width': self.max_width, 'max_height': self.max_height, diff --git a/holoviews/plotting/bokeh/plot.py b/holoviews/plotting/bokeh/plot.py index d6ff6763b0..8dd547e0bc 100644 --- a/holoviews/plotting/bokeh/plot.py +++ b/holoviews/plotting/bokeh/plot.py @@ -631,6 +631,8 @@ def _create_subplots(self, layout, ranges): kwargs['frame_width'] = width if height is not None: kwargs['frame_height'] = height + if c == 0: + kwargs['align'] = 'end' if c == 0 and r != 0: kwargs['xaxis'] = None if c != 0 and r == 0: