I'm trying to plot a line graph in Python using pyplot but I get an error, TypeError: 'float' object is not callable for this line of code:
ycoord = [math.pow(p(1-p),(i-1)) for i in range(1,51)]
I basically have a function p(1-p)^(i-1) that I need to plot a line graph with. I have an array of coordinates 1-51. And I need to get the corresponding y coordinates with that function.
I have also tried: p(1-p)**(i-1), but that has not worked either.
Here is my full code:
def test():
p = 0.2
plt.figure(1)
#create x coordinates [1-51]
xcoord = [i for i in range(1,51)]
#create y coordinates from formula
ycoord = [math.pow(p(1-p),(i-1)) for i in range(1,51)]
plt.plot(xcoord,ycoord)
plt.draw()
plt.show()
test()
p(1-p)wherepis afloat, what do you want to do?p(1-p)does not meanptimes(1-p). You have to explicitly write the multiplication operator. i.e.:p * (1-p). Unlike many other languages, the exponentiation operator in Python is written**not^.