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

Conversation

Projects
None yet
2 participants
@philippjfr
Member

philippjfr commented Jul 27, 2016

As the title says, this allows placing legends outside the axis itself with options that mirror those also present in matplotlib. Positioning is still a bit fiddly and doesn't work perfectly for all plots but the behavior is pretty good overall. Here are some simple examples:

hv.Layout([(hv.Curve(np.random.rand(10,2), label='A') * hv.Curve(np.random.rand(10,2), label='B'))(plot=dict(legend_position=pos)).relabel(pos)
           for pos in ['left', 'right', 'top', 'bottom']]).cols(2)

image

Additionally I also added the legend_columns plot options. In matplotlib this option is an integer to control the number of columns in a legend, bokeh only supports an orientation, which is equivalent to setting the number of columns higher than the number of entries in the legend. For consistency between the backends I'd still argue that naming them the same thing and treating any non-zero legend_columns value as a horizontal legend layout makes sense:

%%opts Overlay [legend_cols=True]
hv.Layout([(hv.Curve(np.random.rand(10,2), label='A') * hv.Curve(np.random.rand(10,2), label='B'))(plot=dict(legend_position=pos)).relabel(pos)
           for pos in ['left', 'right', 'top', 'bottom']]).cols(2)

screen shot 2016-07-27 at 2 45 27 pm

Overall this is an improvement, it's just a bit annoying that bokeh treats legends, axes and anything else that's placed outside the main plot as part of the plot area, which means it won't preserve aspects and squish plots as you see above, but I'm hoping that's something they'll address soon.

@jlstevens

This comment has been minimized.

Member

jlstevens commented Jul 27, 2016

I agree with using legend_cols in this way as I want to avoid different parameters between backends whenever possible. The aspect changes due to the legend are out of control and I also hope that Bokeh handles this better in future.

Looks good. Ready to merge?

@philippjfr

This comment has been minimized.

Member

philippjfr commented Jul 27, 2016

Glad you agree, might file an issue on bokeh to support columns properly, horizontal and vertical orientations are too restrictive. For now it's ready to merge, hopefully we can make the remaining improvements once bokeh has tackled them.

@jlstevens jlstevens merged commit ea6ff1a into master Jul 27, 2016

2 checks passed

continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls First build on bokeh_outside_legends at 46.626%
Details

@jlstevens jlstevens removed the in progress label Jul 27, 2016

@philippjfr philippjfr added this to the v1.6.1 milestone Jul 27, 2016

@philippjfr philippjfr deleted the bokeh_outside_legends branch Sep 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment