plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Add legend 'auto' x|y and/or 'container' (x|y)ref

Open salim-b opened this issue 10 years ago • 48 comments

The problem is that the horizontal legend overlaps the x-axis title. It occurs if the legend is positioned below (rather than to the right of) the plot area using layout = {legend: {"orientation": "h"}};. It aggravates in combination with multiline x-axis titles (using <br> tags).

Currently there's no way to control the spacing between the legend and the plotting area. Everything is auto-scaled, it is useless to set the bottom margin (layout = {margin: {"b": ...}};) in this case because it refers to the space below the legend. The only way to make the whole x-axis title visible is to increase the height of the whole plot until the autoscaling sufficiently spreads the legend and the plotting area apart.

I try to illustrate the problem with the following 3 images which differ only in frame height:

height 700px: example_height700

height 1000px: example_height1000

height 1300px: example_height1300

Here is the above plot hosted on plot.ly.

salim-b avatar Nov 25 '16 17:11 salim-b

Setting layout.legend.y = "auto" and layout.legend.yanchor = "top" helped me to avoid legend overlapping on x-axis title

soadergi avatar Nov 17 '21 17:11 soadergi

Resizing responsive plots multiple times in quick succession can also cause the legend to overlap with the rest of the plot. After the bug occurs, triggering a resize by in- or decreasing by a few px and then returning to the previous page dimensions renders the plot correctly this time.

https://codepen.io/poomse8/pen/KKxVMjx

Nicolas-Yazzoom avatar Feb 20 '23 14:02 Nicolas-Yazzoom

these layout settings allowed me to avoid this issue occurring entirely: 'yref': container 'yanchor': bottom 'xanchor': center 'x': 0.5 'orientation': 'h'

ScottWilliamAnderson avatar Jun 28 '23 15:06 ScottWilliamAnderson

these layout settings allowed me to avoid this issue occurring entirely: 'yref': container 'yanchor': bottom 'xanchor': center 'x': 0.5 'orientation': 'h'

@alexcjohnson @hannahker Does that mean we could close this issue?

archmoj avatar Jun 28 '23 17:06 archmoj

Does that mean we could close this issue?

Obviously I can't speak for the people you mentioned, but my original issue has indeed been fixed since I've last checked (2017). Tested with plotly.js v2.11.1 (included in the plotly R package 4.10.2). 🙂

salim-b avatar Jun 28 '23 18:06 salim-b

these layout settings allowed me to avoid this issue occurring entirely: 'yref': container 'yanchor': bottom 'xanchor': center 'x': 0.5 'orientation': 'h'

@alexcjohnson @hannahker Does that mean we could close this issue?

With the settings, I still need to set a proper layout.margin.b manually to avoid overlapping between the X-axis title and the legend. So I don't think the issue fixed completely...

chaosink avatar Dec 07 '23 15:12 chaosink

Does that mean we could close this issue?

Obviously I can't speak for the people you mentioned, but my original issue has indeed been fixed since I've last checked (2017). Tested with plotly.js v2.11.1 (included in the plotly R package 4.10.2). 🙂

I still have this issue, what settings worked for you? thanks

SimonCoulombe avatar Jun 19 '24 15:06 SimonCoulombe

I still have this issue, what settings worked for you?

The code for the plot in the first post auto-scales perfectly with recent versions of plotly.js:

Bildschirmaufzeichnung vom 19.06.2024, 23:03:30.webm

salim-b avatar Jun 19 '24 21:06 salim-b