Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Scatter Plots

  • Data Collections
  • Scatter Plots
  • Graphs

Data Collection

Collecting data is the most important part of any Machine Intelligence projects.

The most common data to collect are numbers and measurements.

Often data are stored in arrays representing the relationship between values.

This table contains house prices versus size:

Price7889991011141415
Size5060708090100 110120130140150

Scatter Plots

A Scatter Plot has points scattered over an area representing the relationship between two values.

Example

const xArray = [50,60,70,80,90,100,110,120,130,140,150];
const yArray = [7,8,8,9,9,9,10,11,14,14,15];

// Define Data
const data = [{
  x: xArray,
  y: yArray,
  mode:"markers"
}];

// Define Layout
const layout = {
  xaxis: {range: [40, 160], title: "Square Meters"},
  yaxis: {range: [5, 16], title: "Price in Millions"},
  title: "House Prices vs. Size"
};

// Display with Plotly
Plotly.newPlot("myPlot", data, layout);
Try it Yourself ยป


Graphs

A Graph can also be used to show the same values:

Price7889991011141415
Size5060708090100 110120130140150

Source Code

const xArray = [50,60,70,80,90,100,110,120,130,140,150];
const yArray = [7,8,8,9,9,9,10,11,14,14,15];

// Define Data
const data = [{
  x: xArray,
  y:yArray,
  mode:"lines"
}];

// Define Layout
const layout = {
  xaxis: {range: [40, 160], title: "Square Meters"},
  yaxis: {range: [5, 16], title: "Price in Millions"},
  title: "House Prices vs Size"
};

// Display with Plotly
Plotly.newPlot("myPlot", data, layout);

Try it Yourself »


When to Use Scatter Plots

Scatter plots are great for:

  • Seeing the "Big Picture"
  • Compare different values
  • Discovering potential trends
  • Discovering patterns in data
  • Discovering relationships between data
  • Discovering Clusters and Correlations

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.