0
import numpy as np
import matplotlib.pyplot as plt
x=np.array([1,2,3,4,5,6])
def linear(a,b):
    return a*x+b
    plt.plot(x,linear(a,b))
    plt.show()

linear(2,4)

It just gives me the output [6,8,10,12,14,16] but not a plot. I cannot see what's wrong.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Kedy
  • 33
  • 3

1 Answers1

1

You are using return before plot.Change your code to something like this:

import numpy as np
import matplotlib.pyplot as plt
x=np.array([1,2,3,4,5,6])
def linear(a,b):
    return a*x+b   
plt.plot(x,linear(2,4))
plt.show() 
shivsn
  • 7,680
  • 1
  • 26
  • 33
  • Thank you for the heads up shivsn. I wanted the user to be able to specify what the values of a and b are whenever they need. Which is why I did not pre-specify the values of a and b at first. If I put return after plot, it returns an error message. – Kedy Jun 07 '16 at 12:53