THE WORLD'S LARGEST WEB DEVELOPER SITE

Artificial Intelligence

Linear Graphs

  • Linear
  • Slope
  • Intercept

Linear Graphs

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

In general, a linear graph displays function values.

Graph

Example

# Name Axis
plt.title('y = x')
plt.xlabel('x - axis')
plt.ylabel('y - axis')

# Set Axis Range
plt.xlim(0, 10)
plt.ylim(0, 10)

# Set x and y values
x = np.array([0,1,2,3,4,5,6,7,8,9,10])
y = x

# Plot the Graph
plt.plot(x, y)
plt.show()
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 the slope is 1.2:

y = x

Example

# Set x and y values
x = np.array([0,1,2,3,4,5,6,7,8,9,10])
slope = 1.2

# Plot the Graph
plt.plot(x, slope * x)
plt.show()
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 the slope is 1.2 and the intercept is 2:

y = x

Example

# Set x and y values
x = np.array([0,1,2,3,4,5,6,7,8,9,10])
slope = 1.2
intercept = 2

# Plot the Graph
plt.plot(x, slope * x + intercept)
plt.show()
Try it Yourself »