Skip to content

Commit

Permalink
Made shared_axes option supported generally and toggle axiswise when …
Browse files Browse the repository at this point in the history
…disabled
  • Loading branch information
philippjfr committed Jan 17, 2019
1 parent 19b3923 commit 12fe2fc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ class CompositePlot(GenericCompositePlot, MPLPlot):
subplots to form a Layout.
"""

shared_axes = param.Boolean(default=True, doc="""
Whether axes ranges should be shared across the layout, if
disabled switches axiswise normalization option on globally.""")

def _link_dimensioned_streams(self):
"""
Should perform any linking required to update titles when dimensioned
Expand Down
1 change: 1 addition & 0 deletions holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def compute_ranges(self, obj, key, ranges):
# been supplied from a composite plot
return_fn = lambda x: x if isinstance(x, Element) else None
for group, (axiswise, framewise) in norm_opts.items():
axiswise = not getattr(self, 'shared_axes', not axiswise)
elements = []
# Skip if ranges are cached or already computed by a
# higher-level container object.
Expand Down
8 changes: 8 additions & 0 deletions holoviews/plotting/plotly/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class LayoutPlot(PlotlyPlot, GenericLayoutPlot):

vspacing = param.Number(default=0.15, bounds=(0, 1))

shared_axes = param.Boolean(default=True, doc="""
Whether axes ranges should be shared across the layout, if
disabled switches axiswise normalization option on globally.""")

def __init__(self, layout, **params):
super(LayoutPlot, self).__init__(layout, **params)
self.layout, self.subplots, self.paths = self._init_layout(layout)
Expand Down Expand Up @@ -295,6 +299,10 @@ class GridPlot(PlotlyPlot, GenericCompositePlot):

vspacing = param.Number(default=0.05, bounds=(0, 1))

shared_axes = param.Boolean(default=True, doc="""
Whether axes ranges should be shared across the layout, if
disabled switches axiswise normalization option on globally.""")

def __init__(self, layout, ranges=None, layout_num=1, **params):
if not isinstance(layout, GridSpace):
raise Exception("GridPlot only accepts GridSpace.")
Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/plotting/bokeh/testlayoutplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,14 @@ def test_layout_axis_not_linked_mismatching_unit(self):
plot = bokeh_renderer.get_plot(layout)
p1, p2 = (sp.subplots['main'] for sp in plot.subplots.values())
self.assertIsNot(p1.handles['y_range'], p2.handles['y_range'])

def test_layout_shared_axes_disabled(self):
from holoviews.plotting.bokeh import CurvePlot
layout = (Curve([1, 2, 3]) + Curve([10, 20, 30])).opts(shared_axes=False)
plot = bokeh_renderer.get_plot(layout)
cp1, cp2 = plot.traverse(lambda x: x, [CurvePlot])
self.assertFalse(cp1.handles['y_range'] is cp2.handles['y_range'])
self.assertEqual(cp1.handles['y_range'].start, 1)
self.assertEqual(cp1.handles['y_range'].end, 3)
self.assertEqual(cp2.handles['y_range'].start, 10)
self.assertEqual(cp2.handles['y_range'].end, 30)
8 changes: 8 additions & 0 deletions holoviews/tests/plotting/matplotlib/testlayoutplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ def test_layout_dimensioned_stream_title_update(self):
self.assertIn('test: 1', plot.handles['title'].get_text())
plot.cleanup()
self.assertEqual(stream._subscribers, [])

def test_layout_shared_axes_disabled(self):
from holoviews.plotting.mpl import CurvePlot
layout = (Curve([1, 2, 3]) + Curve([10, 20, 30])).opts(shared_axes=False)
plot = mpl_renderer.get_plot(layout)
cp1, cp2 = plot.traverse(lambda x: x, [CurvePlot])
self.assertTrue(cp1.handles['axis'].get_ylim(), (1, 3))
self.assertTrue(cp2.handles['axis'].get_ylim(), (10, 30))

0 comments on commit 12fe2fc

Please sign in to comment.