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

Graph parabola in matplotlib with vertex and 2 'end' points known

Trying to create a parabolic vector of values where the Vertex and two other points along the parabola are known.

Example…

  • Range from 0 to 10
  • Vertex = [5,2]
  • Coordinate 1 = [1,1]
  • Coordinate 2= [10,1]

Example Desired result

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

Any help/advice is greatly appreciated.

Thanks

>Solution :

I would use numpy to adjust a parabola passing by the points with polyfit, and then polyval to evaluate the polinomial found:


import matplotlib.pyplot as plt
import numpy as np

#points
x = [1, 5, 10]
y = [1, 2, 1]

poly_coeffs = np.polyfit(x,y,2) #fit a polynomial with degree=2

#evaluation points vector xx
xmin = 0
xmax = 10
xx = np.linspace(xmin,xmax,100)
yy = np.polyval(poly_coeffs, xx) #y coords

#ploting
plt.figure()
plt.plot(x,y,'or')
plt.plot(xx,yy)
plt.grid()
plt.ylim([-3,4])
plt.xlim([-0.5,12])

this would draw the next image:
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