Hello,
I’m new to plotly and I like that library. I cannot place the legend above or under my plot so that all looks fine.
I have e.g. 15 traces in my plot with 2 y-axes and I had configure a range slider.
My goal is to place the legend above or under the plot. The plot and the range-slider should be align each other.
It tries many combinations of x,y, xanchor, anchor but don’t achieve my goal.
The plotly-reference of the legend ( https://plot.ly/javascript/reference/#layout-legend ) says you can use the 4 mentioned values to specify the position of the legend: xanchor (enumerated: “auto” | “left” | “center” | “right” )
default: "left"
Sets the legend’s horizontal position anchor. This anchor binds the x position to the “left”, “center” or “right” of the legend. yanchor (enumerated: “auto” | “top” | “middle” | “bottom” )
default: "auto"
Sets the legend’s vertical position anchor This anchor binds the y position to the “top”, “middle” or “bottom” of the legend. x (number between or equal to -2 and 3)
default: 1.02
Sets the x position (in normalized coordinates) of the legend. y (number between or equal to -2 and 3)
default: 1
Sets the y position (in normalized coordinates) of the legend.
I not really understand xanchor and yanchor: It binds the x position on e.g. “top” of the legend. Why of the legend? I don’t understand that…
Maybe anbody can help me so that my example looks fine.
I believe the root of the problem is related to how legends and range slidesr impact the margin dimensions. So, to bypass that (buggy) algorithm, you can try setting the margin dimensions manually. I think I manage to get the desired results here: https://jsfiddle.net/74h1oq1k/2/ by setting layout.margin.t to some large value.
Thank you for ur fast answer and the bypass - I have subscribed the issue.
I just noticed a second problem now: The selector options(1m, 6m, …) for the range slider are not visible too. If I search for “selector-rect” in the dom there is nothing. Anybody maybe have an explanation for that behaviour?
Range selectors are only available for date axes at the moment. You can try using Plotly.validate(traces, layout) to confirm attribute interactions like these in the future: