Coloring

Cartesian Line Plot


In [1]:
from sympy.plotting import plot, plot_parametric, plot3d, plot3d_parametric_line, plot3d_parametric_surface

In [2]:
p = plot(sin(x))

If the line_color aesthetic is a function of arity 1 then the coloring is a function of the x value of a point.


In [3]:
p[0].line_color = lambda a : a

p.show()

If the arity is 2 then the coloring is a function of both coordinates.


In [4]:
p[0].line_color = lambda a, b : b

p.show()

Parametric Lines


In [5]:
p = plot_parametric(x*sin(x), x*cos(x), (x,  0, 10))

If the arity is 1 the coloring depends on the parameter.


In [6]:
p[0].line_color = lambda a : a

p.show()

For arity 2 the coloring depends on coordinates.


In [7]:
p[0].line_color = lambda a, b : a

p.show()

In [8]:
p[0].line_color = lambda a, b : b

p.show()

3D Parametric line

Arity 1 - the first parameter. Arity 2 or 3 - the first two coordinates or all coordinates.


In [9]:
p = plot3d_parametric_line(sin(x)+0.1*sin(x)*cos(7*x),

         cos(x)+0.1*cos(x)*cos(7*x),

         0.1*sin(7*x),

         (x, 0, 2*pi))

In [10]:
p[0].line_color = lambda a : sin(4*a)

p.show()

In [11]:
p[0].line_color = lambda a, b : b

p.show()

In [12]:
p[0].line_color = lambda a, b, c : c

p.show()

Cartesian Surface Plot


In [14]:
p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))

Arity 1, 2 or 3 for first, the two first or all coordinates.


In [15]:
p[0].surface_color = lambda a : a

p.show()

In [16]:
p[0].surface_color = lambda a, b : b

p.show()

In [17]:
p[0].surface_color = lambda a, b, c : c

p.show()

In [18]:
p[0].surface_color = lambda a, b, c : sqrt((a-3*pi)**2+b**2)

p.show()

Parametric surface plots

Arity 1 or 2 - first or both parameters.


In [19]:
p = plot3d_parametric_surface(x*cos(4*y), x*sin(4*y), y,

         (x, -1, 1), (y, -1, 1))

In [20]:
p[0].surface_color = lambda a : a

p.show()

In [21]:
p[0].surface_color = lambda a, b : a*b

p.show()

Arrity of 3 will color by coordinates.


In [22]:
p[0].surface_color = lambda a, b, c : sqrt(a**2+b**2+c**2)

p.show()