butiran

plotyl xy-scatter

· 1 min read · edit

code

let cnt = document.getElementById('cnt');
cnt.style.marginLeft = '-1.5em';
cnt.style.marginRight = '0em';

const data1 = {
  x: [1, 2, 3, 4, 5, 6, 7, 8, 9],
  y: [4, 6, 7.5, 8.5, 8.75, 8.5, 7.5, 6, 4],
  mode: 'markers+lines',
  type: 'scatter',
  name: 'Data 1',
};

const data = [data1];

const layout = {
  title: { text: 'Quadratic curve'},
  xaxis: {
    title: {
      text: "x",
      font: {
        family: 'Times',
        size: 16,
        style: 'italic',
      },
    },
  },
  yaxis: {
    title: {
      text: 'y',
      font: {
        family: 'Times',
        size: 16,
        style: 'italic',
      },
    },
  },
  margin: { t: 30, r: 0, b: 40, l: 50 },
  autosize: true,
  height: 300,
};

config = {
  responsive: true,
}

Plotly.newPlot('cnt', data, layout, config);

notes

  • A warm to hot discussion is performed in choosing Plotly.js over Chart.js for xy-scatter plot 1.
  • The plot can be responsive, which is hopefully suitable for smartphone screen 2.

refs


  1. GPT-5, “Local Deployment and Versioning of Plotly.js for XY Charts”, ChatGPT, 23 Nov 2025, url https://chatgpt.com/share/6922dd62-b504-800a-a43b-f29807a73ea3 . [20251123]. ↩︎

  2. GPT-5, “Responsive Plotly.js setup”, ChatGPT, 23 Nov 2025, url https://chatgpt.com/share/6923032b-68c8-800a-888d-c49d3f1f578f [20251123]. ↩︎