Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

      x.append(i)
      y.append(prob_x)

     plt.plot(x,y)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import matplotlib.pyplot as plt

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

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

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading