Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for adding legends outside plot in bokeh #801

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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