Plotly.js defaults to have the legend covering the second y axis. Here is their own code pen example of it happening: https://codepen.io/plotly/pen/36d6c70e8fa17e471fa68788abbed90f
var trace1 = {
x: [1, 2, 3],
y: [40, 50, 60],
name: 'yaxis data',
type: 'scatter'
};
var trace2 = {
x: [2, 3, 4],
y: [4, 5, 6],
name: 'yaxis2 data',
yaxis: 'y2',
type: 'scatter'
};
var data = [trace1, trace2];
var layout = {
title: 'Double Y Axis Example',
yaxis: {title: 'yaxis title'},
yaxis2: {
title: 'yaxis2 title',
titlefont: {color: 'rgb(148, 103, 189)'},
tickfont: {color: 'rgb(148, 103, 189)'},
overlaying: 'y',
side: 'right'
}
};
Plotly.newPlot('myDiv', data, layout);
I cannot get the legend to move more to the right. I have tried adjusting the margin/padding on the plot, the x position of the legend, the margin/padding on the legend, the overall size of the div, and the orientation of the legend.
On the topic of legend orientation, I could potentially put the legend below the plot to solve this problem. However, I am also having trouble implementing that. Here is my legend layout code:
legend: {orientation: 'h',
y: -0.17,
x: 0,
font: {
family:'Roboto',
size: 10,
color: 'rgb(54, 54, 54)'}
},
and here is what my graph looks like:

Clearly there is a lot of code missing here and this isn't a working example of the problem, but the orientation is not changing to horizontal.