我有一个问题,关于下面我计算出来的斜率角度值:
它返回了坡度角的值为7.3度。但是从图表上看,这似乎不正确:
它看起来接近45度。这里有什么问题?
这是我需要计算角度的线:
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
import datetime as dt
import numpy as np
df = yf.download('aapl', '2015-01-01', '2021-01-01')
df.rename(columns = {'Adj Close' : 'Adj_close'}, inplace= True)
x1 = pd.Timestamp('2019-01-02')
x2 = df.index[-1]
y1 = df[df.index == x1].Adj_close[0]
y2 = df[df.index == x2].Adj_close[0]
slope = (y2 - y1)/ (x2 - x1).days
angle = round(np.rad2deg(np.arctan2(y2 - y1, (x2 - x1).days)), 1)
fig, ax1 = plt.subplots(figsize= (15, 6))
ax1.grid(True, linestyle= ':')
ax1.set_zorder(1)
ax1.set_frame_on(False)
ax1.plot(df.index, df.Adj_close, c= 'k', lw= 0.8)
ax1.plot([x1, x2], [y1, y2], c= 'k')
ax1.set_xlim(df.index[0], df.index[-1])
plt.show()
它返回了坡度角的值为7.3度。但是从图表上看,这似乎不正确:
![enter image description here](https://istack.dev59.com/Yud5E.webp)
这是我需要计算角度的线:
![enter image description here](https://istack.dev59.com/KcAZ8.webp)