Tutorials References Menu

Artificial Intelligence

Linear Graphs

  • Linear
  • Slope
  • Intercept

Linear

Linear means straight. A linear graph is a straight line.

In general, a linear graph display function values.

Example

var xValues = [];
var yValues = [];

// Generate values
for (var x = 0; x <= 10; x += 1) {
  xValues.push(x);
  yValues.push(x);
}

// Display using Plotly
var data = [{
  x: xValues,
  y: yValues,
  mode: "lines"
}];

// Define Layout
var layout = {title: "y = x"};
// Display using Plotly
Plotly.newPlot("myPlot", data, layout);
Try it Yourself »

Slope

The slope is the angle of the graph.

The slope is the a value in a linear graph:

y = ax

In this example, slope = 1.2:

Example

var slope = 1.2;
var xValues = [];
var yValues = [];

// Generate values
for (var x = 0; x <= 10; x += 1) {
  xValues.push(x);
  yValues.push(x * slope);
}

// Define Data
var data = [{
  x: xValues,
  y: yValues,
  mode: "lines"
}];
// Define Layout
var layout = {title: "Slope=" + slope};

// Display using Plotly
Plotly.newPlot("myPlot", data, layout);
Try it Yourself »

Intercept

The Intercept is the start value of the graph.

The intercept is the b value in a linear graph:

y = ax + b

In this example, slope = 1.2 and intercept = 2:

Example

var slope = 1.2;
var intercept = 7;
var xValues = [];
var yValues = [];

// Generate values
for (var x = 0; x <= 10; x += 1) {
  xValues.push(x);
  yValues.push(x * slope + intercept);
}

// Define Data
var data = [{
  x: xValues,
  y: yValues,
  mode: "lines"
}];

// Define Layout
var layout = {title: "Slope=" + slope + " Intercept=" + intercept};

// Display using Plotly
Plotly.newPlot("myPlot", data, layout);
Try it Yourself »