hellowill89 hellowill89 - 1 year ago 66
Python Question

Polyfit degree from horizontal

In my project, I have a best-fit line for some points which I got using

. With that, I want to calculate the degree between the returned best-fit line and the horizon. As if the first point in the best-fit line were at the origin. Some of my misunderstanding comes from confusion of what polyfit returns. How best could I get the angle?

Answer Source
import numpy as np
# simulate some data:
x = np.arange(10, dtype=np.float)
b = 1.5
y = 2 * x + b
# fit the data with a 1st degree polynomial
# (1st degree because poster mentions "best-fit *line*"):
cf = np.polyfit(x, y, 1)

It may be useful to watch https://www.brightstorm.com/math/precalculus/advanced-trigonometry/angle-inclination-of-a-line/ on how coefficients of the polynomial (cf[0] = m in the video) relate to the angle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download