Using 'top_left' legend in a Layout plot cuts out a part of the plot
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)
Second layout
(plot4 + plot1 + plot2 + plot3).cols(2)
Third layout
(plot3 + plot4 + plot1 + plot2).cols(2)
Fourth layout
(plot2 + plot3 + plot4 + plot1).cols(2)
Standalone plot (All copacetic)
- [ ] I may be interested in making a pull request to address this
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.
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
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)
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.
Yeah was in a hurry meant https://github.com/holoviz/holoviews/issues/5438 because of frame_* and layout, but not sure anymore 🙃
xref https://github.com/bokeh/bokeh/issues/14492