I have a data frame df
with columns A
and Q
. I am using this code to draw a line of equation on it.
#Actual line of equation, which has to be plotted: Q=alpha*A^beta : ln(Q)=a+b*ln(A) : y = a+b(x)
x = np.log(df['A'])
y = np.log(df['Q'])
#deriving b,a
b,a = np.polyfit(np.log(x), y, 1)
#deriving alpha and beta. By using a = ln(alpha); b = beta -1
alpha = np.exp(a)
beta = b + 1
Q = df['Q'].values
A = df['A'].values
#equation of line
q = alpha * np.power(A,beta)
#plotting the points and line
plt.scatter(A,Q)
plt.plot(A,q, '-r')
plt.yscale('log')
plt.xscale('log')
This gives the following output, which is similar to a regression line.
But I am interested in plotting the same line of the equation as the upper and lower curve/boundary joining the farthest points(perpendicular to the green line) on both sides as shown below with the same slope as that of the continuous green line.