I have just started with Plotly. I am confused about the numbering convention for xaxis
and yaxis
in subplots. The following code makes two subplots, each with two shared x-axis plot:
var data = [
{ xaxis: "x", yaxis: "y", x: [1, 2, 3], y: [10, 20, 30], type: "scatter" },
{ xaxis: "x", yaxis: "y3", x: [2, 3, 4], y: [7, 6, 5], type: "scatter" },
{ xaxis: "x2", yaxis: "y2", x: [3, 4, 5], y: [40, 50, 60], type: "scatter" },
{ xaxis: "x2", yaxis: "y4", x: [4, 5, 6], y: [4, 5, 6], type: "scatter" },
];
var layout = {
grid: { pattern: "independent", rows: 1, columns: 2 },
yaxis3: { overlaying: "y", anchor: "x", side: "right" },
yaxis4: { overlaying: "y2", anchor: "x2", side: "right" }
};
Plotly.newPlot("myDiv", data, layout);
see https://codepen.io/mzaffalon/pen/wvdBRPZ
What does not seem to work is when the main plot has the index for xaxis
and yaxis
different, that is when I replace the expression above xaxis: "x2", yaxis: "y2"
by xaxis: "x2", yaxis: "y3"
as in the code below:
var data = [
{ xaxis: "x", yaxis: "y", x: [1, 2, 3], y: [10, 20, 30], type: "scatter" },
{ xaxis: "x", yaxis: "y2", x: [2, 3, 4], y: [7, 6, 5], type: "scatter" },
{ xaxis: "x2", yaxis: "y3", x: [3, 4, 5], y: [40, 50, 60], type: "scatter" },
{ xaxis: "x2", yaxis: "y4", x: [4, 5, 6], y: [4, 5, 6], type: "scatter" },
];
var layout = {
grid: { pattern: "independent", rows: 1, columns: 2 },
yaxis2: { overlaying: "y", anchor: "x", side: "right" },
yaxis4: { overlaying: "y3", anchor: "x2", side: "right" }
};
Plotly.newPlot("myDiv", data, layout);
see https://codepen.io/mzaffalon/pen/zYwxyyd
I could not find any documentation about the numbering convention: is my observation correct?