How can I automate code to plot a line between two points?

Currently trying to create an automated function that can find a line between two points. Tried testing this function (by plotting) but when I plot the function I get a ‘v-shaped’ line. What changes can I make to complete this function? Thanks.

     import matplotlib.pyplot as plt
     from math import e

     x = [0, 9]
     y = [7, 2]
     m = (y[1]-x[1])/(y[0]-x[0])
     b = m*(y[0]-x[0])+x[1]

     for i in range (-10, 10):
      prob_x = m*i + b



>Solution :

import matplotlib.pyplot as plt

x = [0, 9]
y = [7, 2]
plt.plot(x, y)

You don’t need to do anything, plt.plot returns a line between two points anyway


enter image description here

Leave a Reply