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

renderer.save with matplotlib puts legend outside figure's bbox #993

Closed
llvilanova opened this issue Nov 29, 2016 · 4 comments
Closed

renderer.save with matplotlib puts legend outside figure's bbox #993

llvilanova opened this issue Nov 29, 2016 · 4 comments
Labels
tag: backend: mpl tag: component: plotting type: bug Something isn't correct or isn't working

Comments

@llvilanova
Copy link

Seems like holoviews is not accouting for the legend when calculating a figure's bounding box with the matplotlib backend. I'm using holoviews version 1.6.2, matplotlib 1.5.3 and python 2.7.12+.

Here's a minimal failing example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import holoviews as hv
import holoviews.plotting.mpl
renderer = hv.Store.renderers['matplotlib'].instance(fig='svg', holomap='gif')
options={
    "Bars": dict(
        plot=dict(
            color_by=["stack"],
            legend_position="top",
        ),  
    ),  
}
data = [(("foo1", "bar1", "baz1"), 1)]
fig = hv.Bars(data,
              kdims=['Benchmark', 'Tool', ''], vdims=['Execution time [ms]'])
renderer.save(fig, "/tmp/figure", options=options)
@philippjfr philippjfr added type: bug Something isn't correct or isn't working tag: backend: mpl tag: component: plotting labels Nov 29, 2016
@philippjfr
Copy link
Member

philippjfr commented Nov 29, 2016

Could you paste the saved image here? For me the output looks correct:

screen shot 2016-11-29 at 9 14 47 pm

Edit: The gap between the two levels of axis labels could be increased though.

@llvilanova
Copy link
Author

Here's what I get (the same happens for SVG, PNG and PDF):

figure

Setting this on options fixes it without me having to modify holoview's code:

    def finalize(plot, element):
        # make sure the legend is accounted for during bbox calculation
        axis = plot.handles["axis"]
        legend = axis.get_legend()
        plot.handles["bbox_extra_artists"] += [legend]
    options={
        "Bars": dict(
            plot=dict(
                color_by=["stack"],
                legend_position="top",
                final_hooks=[finalize],
            ),
        ),
    }

@philippjfr
Copy link
Member

I'll keep investigating but if you've got a minute could you try it again on holoviews master?

@llvilanova
Copy link
Author

I just tried master and it also fails (simply cloned it and prepended its directory into sys.path). See pull request #998 for a fix (I'm not sure that's the proper way to do it).

philippjfr added a commit that referenced this issue Nov 30, 2016
Make sure legends are always part of the bbox calculations (fixes #993)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: backend: mpl tag: component: plotting type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

2 participants