Graphing a Parabola using Matplotlib in Python -


i trying graph simple parabola in matplotlib , confused how supposed plot points on parabola. far, have:

import matplotlib.pyplot plt a=[] b=[] y=0 x=-50 while x in range(-50,50,1):     y=x^2+2*x+2     a=[x]     b=[y]     fig= plt.figure()     axes=fig.add_subplot(111)     axes.plot(a,b)     plt.show()     x= x+1 

this approach few changes possible make work (because it's clear you're beginner , learning exercise). changes made were:

  1. moved plt.figure, , other plotting statements out of loop. loop gives data plot, , plot once loop finished.

  2. changed x^2 x**2.

  3. changed while for in main loop control statement.

  4. commented out few lines weren't doing anything. had same source of error (or non-utility, really): in loop, x set in loop control line , y calculated directly, don't need give them initial values or increment x, though have had these steps while loop.

enter image description here

here code:

import matplotlib.pyplot plt  a=[] b=[] # y=0 # x=-50  x in range(-50,50,1):     y=x**2+2*x+2     a.append(x)     b.append(y)     #x= x+1  fig= plt.figure() axes=fig.add_subplot(111) axes.plot(a,b) plt.show() 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -