Skip to content

Commit

Permalink
Merge pull request #801 from ioam/bokeh_outside_legends
Browse files Browse the repository at this point in the history
Added support for adding legends outside plot in bokeh
  • Loading branch information
jlstevens authored Jul 27, 2016
2 parents 843eeed + db2b8cd commit ea6ff1a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,20 +705,30 @@ class OverlayPlot(GenericOverlayPlot, ElementPlot):
legend_position = param.ObjectSelector(objects=["top_right",
"top_left",
"bottom_left",
"bottom_right"],
"bottom_right",
'right', 'left',
'top', 'bottom'],
default="top_right",
doc="""
Allows selecting between a number of predefined legend position
options. The predefined options may be customized in the
legend_specs class attribute.""")

legend_cols = param.Integer(default=False, doc="""
Whether to lay out the legend as columns.""")

tabs = param.Boolean(default=False, doc="""
Whether to display overlaid plots in separate panes""")

style_opts = legend_dimensions + line_properties + text_properties

_update_handles = ['source']

legend_specs = {'right': dict(pos='right', loc=(5, -40)),
'left': dict(pos='left', loc=(0, -40)),
'top': dict(pos='above', loc=(120, 5)),
'bottom': dict(pos='below', loc=(60, 0))}

def _process_legend(self):
plot = self.handles['plot']
if not self.show_legend or len(plot.legend) == 0:
Expand All @@ -745,7 +755,9 @@ def _process_legend(self):
if legend_fontsize:
plot.legend[0].label_text_font_size = legend_fontsize

plot.legend.location = self.legend_position
if self.legend_position not in self.legend_specs:
plot.legend.location = self.legend_position
plot.legend.orientation = 'horizontal' if self.legend_cols else 'vertical'
legends = plot.legend[0].legends
new_legends = []
for label, l in legends:
Expand All @@ -754,6 +766,13 @@ def _process_legend(self):
legend_labels.append(label)
new_legends.append((label, l))
plot.legend[0].legends[:] = new_legends
if self.legend_position in self.legend_specs:
legend = plot.legend[0]
plot.legend[:] = []
legend.plot = None
leg_opts = self.legend_specs[self.legend_position]
legend.location = leg_opts['loc']
plot.add_layout(plot.legend[0], leg_opts['pos'])


def _init_tools(self, element):
Expand Down

0 comments on commit ea6ff1a

Please sign in to comment.