Creating plots from 2-D values generated in a for loop in Python -


i'm creating trail of (x,y) co-ordinates generated in for-loop. plot pops , it's blank. can noob out?

import random import math import matplotlib.pyplot pl  x = 0 y = 0  dx = 0 dy = 0 v = 2  n=100 pl.figure() pl.hold(true)  in range(1,n):     dx = random.uniform(-2,2)     x = x+dx     y += ((v**2 - dx**2)**(0.5))*(random.randint(-1,1))     pl.plot(x,y)     print(x,y)  pl.show() 

you trying plot line each of random points: graph blank because each single point isn't connected other. try building list of points , plotting list line graph:

xarr, yarr = [], [] in range(1,n):     dx = random.uniform(-2,2)     x = x+dx     y += ((v**2 - dx**2)**(0.5))*(random.randint(-1,1))     xarr.append(x)     yarr.append(y) pl.plot(xarr,yarr)  pl.show() 

enter image description here


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -