Skip to content

Commit

Permalink
Fix Grid level alignment (#3957)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 20, 2019
1 parent 7925860 commit 237de09
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/user_guide/Plotting_with_Bokeh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
4 changes: 4 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.""")

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 237de09

Please sign in to comment.