Reputation: 29
I was wondering how I overlap these two graphs in matplotlib. One is a plot with dots, the other one named 'trendlijn' is a linear line.
I've tried to use alpha but it didn't work. Does someone have a suggestion for me? I am not that good in programming, so please, take your time to explain the steps you've made, thanks.
Here's the code.
import matplotlib.pyplot as plt
from scipy.stats import linregress
import numpy as np
d01 = [200, 180, 160, 140, 120]
di1 = [122, 130, 143, 165, 204]
d02 = [200, 180, 160, 140, 120]
di2 = [78, 82, 85, 95, 107]
multiply_y = np.multiply(d01, di1)
print(multiply_y)
add_x = np.add(d01, di1)
print(add_x)
a, b, r, p, s_a = linregress(add_x, multiply_y)
print ('Richtingcoëfficent=' ,a ,'\n','Standaardafwijking van het gemiddelde=', s_a*3, '\n', 'Snijpunt Y-as=', b)
plt.plot([add_x[0],add_x[-1]],[a*add_x[0]+b,a*add_x[-1]+b], label='trendlijn')
plt.plot(add_x, multiply_y, 'o', label='Metingen')
plt.grid(b=None, which='major', axis='both')
plt.xlabel('$x = d0 + di$ ($m$)')
plt.ylabel('$y = d0*d1$ ($m$)')
plt.legend(loc='lower right')
Upvotes: 0
Views: 329
Reputation: 2719
add_x[0]
is not the smallest number in your list and add_x[-1]
is not the biggest. So your code do not cover all range of values. You can use min(add_x)
and max(add_x)
instead.
plt.plot([min(add_x), max(add_x)],[a*min(add_x)+b, a*max(add_x)+b], label='trendlijn')
Upvotes: 1