This is wierd. I want to have a few traces on one subplot and then a few more on a different subplot, but only one traces is showing up per subplot.
One thing that I noticed is that before calling “newplot” then layout seems reasonable enough but after calling newplot then layout.yaxis.domain has been turned into “[0.7, 1, 0.5263157894736842: undefined]”.
I guess I am missing something silly, but I can’t find it…
T.
// Create data for the first subplot (three traces)
const trace1 = {
x: [1, 2, 3],
y: [4, 5, 6],
yaxis: 'y1', // Assign to the first y-axis
type: 'scatter',
mode: 'lines',
name: 'Subplot 1 Trace 1'
};
const trace2 = {
x: [1, 2, 3],
y: [6, 5, 4],
yaxis: 'y2', // Assign to the second y-axis
type: 'scatter',
mode: 'lines',
name: 'Subplot 1 Trace 2'
};
const trace3 = {
x: [1, 2, 3],
y: [2, 1, 2],
yaxis: 'y3', // Assign to the third y-axis
type: 'scatter',
mode: 'lines',
name: 'Subplot 1 Trace 3'
};
// Create data for the second subplot (two traces)
const trace4 = {
x: [1, 2, 3],
y: [8, 9, 10],
yaxis: 'y4', // Assign to the fourth y-axis
type: 'scatter',
mode: 'lines',
name: 'Subplot 2 Trace 1'
};
const trace5 = {
x: [1, 2, 3],
y: [10, 9, 7],
yaxis: 'y5', // Assign to the fifth y-axis
type: 'scatter',
mode: 'lines',
name: 'Subplot 2 Trace 2'
};
// Define layout for the subplots with individual y-axes
// Define layout for the subplots
const layout = {
title: 'Two Subplots with Different Traces and Individual Y-Axes',
grid: {rows: 2, columns: 1},
xaxis: {range: [0, 5], domain: [0.1, 0.9]}, // Adjust x-axis domain to make space for the y-axis text
yaxis: {range: [0, 10],title: 'Y-axis 1', side: 'left', position:0, anchor: 'free' ,
domain: [0.7,1.0]}, // Y-axis 1 with manual position
yaxis2: {title: 'Y-axis 2', side: 'right', position: 0.95, anchor: 'free',
domain: [0.7,1.0]}, // Y-axis 2 with manual position
yaxis3: {title: 'Y-axis 3', anchor: 'free', side: 'left', position: 0.08,
domain: [0.7,1.0]}, // Y-axis 3 with manual position
yaxis4: {title: 'Y-axis 4', anchor: 'free', position: 0.00, domain: [0.0,0.5]}, // Y-axis 4 with manual position
yaxis5: {title: 'Y-axis 5', position: 0.08,
anchor: 'free', domain: [0.0,0.5]}, // Y-axis 5 with manual position
};
// Create the subplots
const traces = [trace1, trace2, trace3, trace4, trace5];
Plotly.newPlot('myDiv', traces, layout);