hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Using 'top_left' legend in a Layout plot cuts out a part of the plot

Open Azaya89 opened this issue 7 months ago • 5 comments

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Software Version Info
Bokeh: 3.7.3
hvPlot: 0.11.3.dev47+g816845f.d20250515
Pandas: 2.2.3

Description of expected behavior and the observed behavior

Expected behaviour Creating a layout of multiple scatter plots in a 2 column grid should show the full plots.

Observed behaviour Using legend='top_left' in any of the plots will cut parts of the plot out.

Complete, minimal, self-contained example code that reproduces the issue

import hvplot.pandas  # noqa
import hvsampledata

df = hvsampledata.penguins("pandas")

width = 300

plot1 = df.hvplot.scatter(x='flipper_length_mm', y='body_mass_g', by='species',
                        title="Default: legend=right", frame_width=width)
plot2 = df.hvplot.scatter(x='flipper_length_mm', y='body_mass_g', by='species',
                        legend='left', title="legend=left", frame_width=width)
plot3 = df.hvplot.scatter(x='flipper_length_mm', y='body_mass_g', by='species',
                        legend='top_right', title="legend=top_right", frame_width=width)
plot4 = df.hvplot.scatter(x='flipper_length_mm', y='body_mass_g', by='species',
                        legend='top_left', title="legend=top_left", frame_width=width) # The culprit

Screenshots or screencasts of the bug in action

First layout

(plot1 + plot2 + plot3 + plot4).cols(2)

Image

Second layout

(plot4 + plot1 + plot2 + plot3).cols(2)

Image

Third layout

(plot3 + plot4 + plot1 + plot2).cols(2)

Image

Fourth layout

(plot2 + plot3 + plot4 + plot1).cols(2)

Image

Standalone plot (All copacetic)

Image

  • [ ] I may be interested in making a pull request to address this

Azaya89 avatar May 15 '25 18:05 Azaya89

Can you please try to reproduce with pure HoloViews code? I suspect it is not an hvPlot issue. It might also be good to check how the layout gets rendered with different browsers.

maximlt avatar May 16 '25 08:05 maximlt

Pure Bokeh example, when something like this is cropped, it is usually not even a holoviews problem. @mattpap, I think this will fall under the same underlying problem as seen in https://github.com/holoviz/holoviews/issues/6527

Image

from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource, Legend
from bokeh.plotting import figure, show
from bokeh.io import output_notebook

output_notebook()


def make_scatter_with_external_legend(legend_position):
    p = figure(title=legend_position, frame_width=300, frame_height=300)

    source = ColumnDataSource(dict(x=[1, 2], y=[1, 2]))
    r = p.scatter(source=source)
    legend = Legend(items=[("test", [r])], title=legend_position)
    p.add_layout(legend, legend_position)
    return p


plot1 = make_scatter_with_external_legend("right")
plot2 = make_scatter_with_external_legend("left")
plot3 = make_scatter_with_external_legend("above")
plot4 = make_scatter_with_external_legend("below")
grid = gridplot([[plot1, plot2], [plot3, plot4]])
show(grid)

hoxbro avatar May 16 '25 08:05 hoxbro

I think this will fall under the same underlying problem as seen in https://github.com/holoviz/holoviews/issues/6527

No. This is a case of frame_width and frame_height not working in complex layouts. I started issue bokeh/bokeh#14492 for tracking this.

mattpap avatar May 16 '25 16:05 mattpap

Yeah was in a hurry meant https://github.com/holoviz/holoviews/issues/5438 because of frame_* and layout, but not sure anymore 🙃

hoxbro avatar May 16 '25 16:05 hoxbro

xref https://github.com/bokeh/bokeh/issues/14492

maximlt avatar Jun 23 '25 08:06 maximlt