Inset Plots in JavaScript

How to make an inset graph in D3.js-based javascript charts.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.

var trace1 = {
  x: [1, 2, 3],
  y: [4, 3, 2],
  type: 'scatter'
};

var trace2 = {
  x: [20, 30, 40],
  y: [30, 40, 50],
  xaxis: 'x2',
  yaxis: 'y2',
  type: 'scatter'
};

var data = [trace1, trace2];

var layout = {
  yaxis2: {
    domain: [0.6, 0.95],
    anchor: 'x2'
  },
  xaxis2: {
    domain: [0.6, 0.95],
    anchor: 'y2'
  }
};

Plotly.newPlot('myDiv', data, layout);
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"var trace1 = {\n x: [1, 2, 3],\n y: [4, 3, 2],\n type: 'scatter'\n};\n\nvar trace2 = {\n x: [20, 30, 40],\n y: [30, 40, 50],\n xaxis: 'x2',\n yaxis: 'y2',\n type: 'scatter'\n};\n\nvar data = [trace1, trace2];\n\nvar layout = {\n yaxis2: {\n domain: [0.6, 0.95],\n anchor: 'x2'\n },\n xaxis2: {\n domain: [0.6, 0.95],\n anchor: 'y2'\n }\n};\n\nPlotly.newPlot('myDiv', data, layout);\n"}">