pythonmatplotlibsympyparametric-equations

parametric plot using matplotlib Python


I would like to write a program which draw parametric plot. I have to use matplotlib and sympy with n steps, n is the number of segments approximating the curve. I have a problem with using n. I put a program that doesn't use n and library matplotlib.

from sympy import *
from sympy.plotting import plot_parametric
import math

def param(x,y,t,a,b,n):
    t = Symbol('t')
    return plot_parametric(x,y,(t,a,b))

t = Symbol('t')
x=cos(t)
y=sin(t)
n=100
a=0
b=2*pi
plot_parametric(x,y,(t,0,2*pi),n)

Solution

  • To change the number of points, you need to change the parameter adaptive to False and set nb_of_points. See the docs for more details and more parameters.

    Default, adaptive is set to True in which case nb_of_points is ignored. When adaptive is used, the algorithm calculates more points where the curve changes a lot and less where it changes little.

    To draw a circle with 20 points (there will be 19 segments):

    plot_parametric(x, y, (t, 0, 2 * pi), nb_of_points=20, adaptive=False)