plotparametric.py

Created by ews31415

Created on December 27, 2020

638 Bytes

Template for plotting parametric equations (x(t), y(t))


from math import *
from matplotlib.pyplot import *
# EWS 2020-12-26

# define parametric here
def x(t):
  x=t**2-3*t+1
  return x
def y(t):
  y=abs(2*sin(t))
  return y

# main routine
ta=float(input('start? '))
tb=float(input('stop? '))
n=float(input('n? '))
tc=(tb-ta)/n

# build
tp=ta
xp=x(tp)
yp=y(tp)
xlist=[xp]
ylist=[yp]

while tp<tb:
  tp=tp+tc
  xp=x(tp)
  yp=y(tp)
  xlist.append(xp)
  ylist.append(yp)
  
# plot routine

# set axes
xa=min(xlist)
xb=max(xlist)
ya=min(ylist)
yb=max(ylist)
axis((xa,xb,ya,yb))
axis(True)

# select color, type color
ch="red"

# plot points
plot(xlist,ylist,color=ch)
show()