Technology Musings

August 05, 2012

Snippets / Simple Sage Plots for Teaching Functions


I'm teaching calculus to some homeschool students this year, and I wanted to have a bunch of function plots printed out to show them.  Therefore, I turned to Sage, which I have never used.  It is great!  You have to know a few other math software pieces to really understand it, but it's not that bad.  Someone needs to do a general "how to use sage", and some day I might.

Anyway, here's my quick function for plotting graphs for students that some of you might like.

In one of the evaluation boxes, type the following:

def simpleplot(f, range=(-5,5,-5,5)):
p = plot(f, (x, range[0], range[1]))
p += text("$" + latex(f) + "$", (0, range[2] - (range[3] - range[2]) * 0.1), fontsize=30, rgbcolor=(1,0,0))
p.axes_range(range[0], range[1], range[2], range[3])
show(p, figsize=12)

What this does is create a function called "simpleplot" which will do the following:

  • Plot the given function on a default domain of -5, 5
  • Typeset the function using LaTeX, and insert the function slightly below the graph (I calculated it at 10% of the graph size).  It prints in red at 30 point size.
  • Set the axes to be -5, 5, -5, 5 (I used uniform axes on all the functions so they can compare the differences between graphs easier)
  • Draw the whole thing at 3x the normal size (figsize=12 - default is 4).

Now, I can just do:


And it gives me my output!