SAGE : Graphing

Sage has a plethora of ways to graph expressions including options to enhance the appearance of every part of the graph. To get a full list of options evaluate help(plot). We'll start out with a very simple code, and add options.

Graphing a Single Expression

1. Plot $y=x^2$. By default, it will plot from $x=-1$ to $x=1$.



2. Change the domain to $-3\le x \le3$, and change the output to $-1\le y \le 7$.



3. Change the line style, color, and thickness.


Other options for linestyle are ":", "-.", "None"



Plotting Several Expressions

There are several ways to plot more than one expression.

4. Plot $y=x^2$ and $y=2x+3$

Method 1: using a list of expressions.


Method 2: storing the plots in variables and combining them together.


Method 3: Use only one graphic object, and keep adding other graphic objects to it.



Rational Functions and Vertical Asymptotes

5. Graph the rational function: $y=\frac{x+2}{x^2-2x-3}$


The vertical scale is too extreme and needs to be changed.


The vertical lines are artifacts of the plotting process. These occur when the plot goes from a negative extreme value to a positive extreme value, (or visa versa) and can be removed using detect_poles='False':


To show the vertical asymptotes set detect_poles='show'.



Implicit Plots

6. Plot the conic $x^2-xy+5y^2+4x-8y=15$



Trigonometric Plots

7. Graph the trigonometric function $f(x)=\sin(x-\frac{\pi}{6})+\frac{1}{2}$, and mark the $x$-axis in terms of $\pi$;



Parametric Plots

8. Graph the parametric equation described by $x=(t-1)^2$ and $y=0.2\sin(\pi t)$ for $0\le t \le2$.


Polar Graphs

Plot the polar equation $r=3+8cos(\theta)$