Template for plotting functions in the form f(x).
from math import * from matplotlib.pyplot import * # EWS 2020-12-26 # define function here def f(x): y=1/(x**2+1) return y # main routine xa=float(input('start? ')) xb=float(input('stop? ')) n=float(input('n? ')) xc=(xb-xa)/n # build xp=xa yp=f(xp) xlist=[xp] ylist=[yp] while xp<xb: xp=xp+xc yp=f(xp) xlist.append(xp) ylist.append(yp) # plot routine # set axes ya=min(ylist) yb=max(ylist) axis((xa,xb,ya,yb)) axis(True) grid(True) # select color, type color ch="blue" # plot points plot(xlist,ylist,color=ch) show()