plotparametric.py

Created by ews31415

Created on December 26, 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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.