0

I have plotted the x-axis and y-axis on the data points.

Now there are 2 tasks.

  1. Draw a diagonal line passing roughly through the middle of data points(Consider the black line in the picture below).
  2. Calculate the angle between the horizontal blue line and the line we draw in task 1.

Note - I have generated the following figure through matplotlib. You can suggest a solution through matplotlib or any other library.

Thanks in advance..

enter image description here

  • 1
    For 1. https://stackoverflow.com/questions/18299523/basic-example-for-pca-with-matplotlib – Daniel Jun 20 '22 at 21:28
  • 1
    For 2. https://stackoverflow.com/questions/28260962/calculating-angles-between-line-segments-python-with-math-atan2 – Daniel Jun 20 '22 at 21:30

1 Answers1

0

(1) There is plentiful literature on how to compute the line of best fit through an array of n-dimensional points using a sequence of matrix transformations (I recommend NumPy for this).

(2) This is a straightforward mathematical translation: if the slope of your line is m = (rise) / (run), then we have a right triangle under the line. Because tan(x) = (opp) / (hyp) = (rise) / (run), then the angle can be found with arctan((rise) / (run)) = arctan(m), where m is the slope of your line.

dsillman2000
  • 976
  • 1
  • 8
  • 20