Examples of nice parametric curves


In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Firstly we define simple function to draw colorfull parametric plots


In [2]:
from matplotlib.collections import LineCollection

def paramshow(x, y, t, cmap='hsv'):
    points = array([x, y]).T.reshape(-1, 1, 2)
    segments = concatenate([points[:-1], points[1:]], axis=1)
    lc = LineCollection(segments, cmap=get_cmap(cmap),
                        norm=Normalize(0, max(t)))
    lc.set_array(t)
    lc.set_linewidth(3)
    gca().add_collection(lc)
    axis('equal')
    show()

So to draw ellipse with axes a and b rotated from x-axis by phi


In [3]:
# define variables
a, b, phi = 3, 1, pi/4
# define parameter
t = linspace(0,2*pi, 1000)
# define x(t) and y(t)
x = a*cos(t)*cos(phi) - b*sin(t)*sin(phi)
y = a*cos(t)*sin(phi) + b*sin(t)*cos(phi)
# plot
paramshow(x, y, t)


Another example


In [4]:
a,b,c = 50, 30, 0.1
t = linspace(0, 2*pi/c, 1000)
x = a*cos(t) + b*cos(c*t)
y = a*sin(t) - b*sin(c*t)
paramshow(x, y, t)


Here is example of mystery curve


In [5]:
a, b = 7, 17
t = linspace(0,2*pi, 1000)
x = cos(t) + cos(a*t)/2 + sin(b*t)/3
y = sin(t) + sin(a*t)/2 + cos(b*t)/3
paramshow(x, y, t)


And of course beautiful butterfly curve...


In [6]:
t = linspace(0,10*pi,5000)
x = sin(t)*(exp(cos(t))-2*cos(4*t)-(sin(t/12)**5))
y = cos(t)*(exp(cos(t))-2*cos(4*t)-(sin(t/12)**5))
paramshow(x, y, t)


Another flower-like curve


In [7]:
t = linspace(0,2*pi, 1000)
a, b = 3, 5
x = cos(a*t)*(1-sin(b*t))
y = sin(a*t)*(1-sin(b*t))
paramshow(x, y, t)



In [8]:
from IPython.core.display import HTML
def css_styling():
    styles = open("./css/sg2.css", "r").read()
    return HTML(styles)
css_styling()


Out[8]: