## Creating mathematical illustrations with `figures.py`

To get started:

1. Download `python` from http://www.python.org/ and install. (Python is already installed on macs.)

Make sure that your system environment variable `PATH` incluldes python.

2. Download `piscript` from http://www.math.ubc.ca/~cass/piscript/ and follow the installation instructions in the manual.

Make sure that your `PYTHONPATH` environment variable includes the location of the installation.

3. Download `figures.py` from here and put it in some safe place.

Make sure that your `PYTHONPATH` environment variable includes that location too.

4. Start drawing!

Anatomy of a figure

```from figures import *

width = 200                    # in points where 1 point = 1/72"
height = 200
margin = 5
beginfigure("example1", width, height)
setupcoordinates( [margin, margin, width-margin, height-margin],
[-2, -2, 2, 2])

endfigure()
```

 ```grid = Grid([-2,0.5,2], [-2,0.5,2], color = lightgray) grid.draw() Axes().draw() ``` ```axes = Axes() axes.draw() axes.sethticks([-2,1,2]) axes.setvticks([-2,1,2]) axes.drawticks() axes.setlabels([-2,1,2], [-2,1,2]) axes.drawlabels() ``` ```cliptoboundingbox() f = Function(lambda x: x*x*x - 2*x) Graph(f, color=blue).draw() ``` ```x0 = -0.5 tangent = f.tangentline(x0) Graph(tangent, domain = [x0-0.75, x0+0.75], color=lightred).draw() point = Point([x0, f.value(x0)], 2.5, fillcolor=red) point.fill() point.draw() ``` ```cliptoboundingbox() f = Function(lambda x: x*x) rs = RiemannSum(f, 10, fillcolor=orange, domain=[0,1], style=RiemannSum.RIGHT) rs.fill() rs.draw() Graph(f, color=blue, linewidth=2).draw() ``` ```Label(r"\$y=x^2\$", [1,1], offset=[-3,3], alignment="rb", scale=1.2).draw() ``` ```def f(x,y): return y*y - x*x*x + x def g(x): return x*x*x - x import math root = math.sqrt(1/3.0) Implicit(f, 0, color = darkmagenta).draw() Implicit(f, 1, color = darkorange).draw() Implicit(f, g(-root), color=darkcyan, initialdepth=6).draw() Label(r"\$y^2 - x^3 + x = k\$", [0, 1.5], alignment = "rb", offset=[-4,0]).draw() ``` ```gridrange = [-10, 1, 10] Grid(gridrange, gridrange, color=0.9).draw() save() atransform(v0, v1) Grid([-10,1,10], [-10,1,10], color=0.5).draw() restore() vec = Vector(v0, arrowwidth=1.5, fillcolor=red, color=red) vec.fill() vec.draw() vec = Vector(v1, arrowwidth=1.5, fillcolor=red, color=red) vec.fill() vec.draw() ```

Ingredients

• GeneralPath
• Line
• Area
• Vector
• SlopeField
• Box
• Polygon
• Point
• Ellipse
• Circle
• Function
• RiemannSum
• AreaBetweenCurves
• Axes
• Label
• Graph
• ParametricCurve
• Grid
• Lagrange
• Hermite
• Derivative
• Antiderivative
• Implicit

Miscellaneous Examples

 example1.py example2.py example3.py example4.py example5.py example6.py example7.py example8.py example9.py example10.py test.py test1.py test2.py test3.py test4.py secant.py secant.py secant.py secant.n.tangent.py labeltest.py