Linear Graphs

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

Linear

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

In general, a linear graph display function values.

// Generate values var xValues = []; var yValues = []; 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"}]; var layout = {title: "y = x"}; Plotly.newPlot("myPlot1", data, layout);

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);

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:

var slope = 1.2; // Generate values var xValues = []; var yValues = []; for (var x = 0; x <= 10; x += 1) { xValues.push(x); yValues.push(x * slope); } // Display using Plotly var data = [{x:xValues, y:yValues, mode:"lines"}]; var layout = {title: "Slope=" + slope}; Plotly.newPlot("myPlot2", data, layout);

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);

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:

var slope = 1.2; var intercept = 7; // Generate values var xValues = []; var yValues = []; for (var x = 0; x <= 10; x += 1) { xValues.push(x); yValues.push(x * slope + intercept); } // Display using Plotly var data = [{x:xValues, y:yValues, mode:"lines"}]; var layout = {title: "Slope=" + slope + " Intercept=" + intercept}; Plotly.newPlot("myPlot", data, layout);

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);