Assignment 4
Assignment 4
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
def myfunc(x):
plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()
output:-
Example Explained
What is Matplotlib?
If SciPy uses NumPy underneath, why can we not just use NumPy?
SciPy has optimized and added functions that are frequently used in
NumPy and Data Science.
Create the arrays that represent the values of the x and y axis:
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
Create a function that uses the slope and intercept values to return a new
value. This new value represents where on the y-axis the corresponding x
value will be placed:
def myfunc(x):
return slope * x + intercept
Run each value of the x array through the function. This will result in a
new array with new values for the y-axis:
plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()