%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Alex Clemesha, July 30, 2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{beamer}
\usepackage{beamerthemesplit}
\usepackage{graphicx}
\usepackage{color}
\definecolor{dbluecolor}{rgb}{0,0,0.6}
\definecolor{dredcolor}{rgb}{.5,0.0,0.0}
\definecolor{dgreencolor}{rgb}{0,0.4,0}
\newcommand{\dred}{\color{dredcolor}\bf}
\newcommand{\dblue}{\color{dbluecolor}\bf}
\newcommand{\dgreen}{\color{dgreencolor}\bf}
\newcommand{\bc}[1]{\color{dbluecolor}\tt{#1}}

\title{Mathematica-like Graphics in SAGE}
\author{Alex Clemesha}
\date{August 17 2006}
\institute{University of Washington}

\begin{document}

\frame
{
\titlepage
}

%%%

\frame
{
\frametitle{Outline}

\begin{enumerate}

\item{\dblue Motivation}\\
The advantages of Mathematica-like plotting.
\vspace{1ex} 
\item{\dblue Structure}\\
Quick layout discussion SAGE's Graphics code.
\vspace{1ex} 
\item{\dblue Examples}\\
Typical usage of the plotting functionality\\
with the SAGE notebook.

\end{enumerate}
}

%%% 

\begin{frame}

\frametitle{What already exits - the 'big' systems}

{\bf How do two of the largest Computer Algebra Systems,\\ 
Matlab and Mathematica, deal with Graphics?\\}
\vspace{1ex} 
\vspace{1ex} 

{\dgreen Matlab is more 'data' oriented.\\}
\begin{itemize}
 \item Visualize a list or array of data
 \end{itemize}
\vspace{1ex} 
{\dgreen Mathematica is more 'functional' oriented.\\}
\begin{itemize}
 \item Visualize a mathematical function over a specified range
 \end{itemize}
\vspace{1ex} 
For {\dblue SAGE} we feel the {\bf Mathematica} approach is more natural.
\end{frame}

%%%

\begin{frame}[fragile]

\frametitle{SAGE's approach to graphics}

Instead of reinventing the wheel (or using Gnuplot), we choose to\\
use {\dblue matplotlib by John Hunter}\\ 
\vspace{1ex} 
\vspace{1ex} 
...but {\bf matplotlib} provides users a very {\dgreen ``Matlab-like''} interface,\\
because after all that's what \emph{it was designed to do}. \\
\vspace{1ex} 
\vspace{1ex} 
So instead we wrap matplotlib's classes with our own {\dgreen``Mathematica-like''} interface.\\
\vspace{1ex} 
{\bf Simplest example:}
\begin{verbatim}
sage: plot(f, 0, 2*pi) #f is any 'callable' function
\end{verbatim}
\end{frame} 

%%%%

\begin{frame}[fragile]

\frametitle{SAGE's usage of matplotlib}
\begin{verbatim}
from matplotlib.figure import Figure 
\end{verbatim}
{\dgreen Once we have an instance}
\begin{verbatim}
fig = Figure()
\end{verbatim}
{\dgreen we can then add one or several 'subplots' to the figure:}
\begin{verbatim}
subplot = fig.add_subplot(111)
\end{verbatim}
From there we can use {\bf matplotlib's} graphics primitives\\
(which are all methods of a \emph{subplot} instance) to construct\\
\emph{axes, graphic primitives and plotting functions}\\
that very closely follow that of {\bf Mathematica's}.
\end{frame}

%%%

\begin{frame}[fragile]
\frametitle{SAGE's usage of matplotlib}
{\dgreen Classes that handle the generation of the image files.\\}
{\dblue SAGE} works well without a GUI toolkit.  For example, the\\
notebook, by default, renders images to png for viewing.\\
{\dblue for png files:}
\begin{verbatim}
FigureCanvasAgg
\end{verbatim}
{\dblue for ps or eps files:}
\begin{verbatim}
FigureCanvasPS
\end{verbatim}
{\dblue for svg files}
\begin{verbatim}
FigureCanvasSVG
\end{verbatim}

\end{frame}

%%

\begin{frame}[fragile]

\frametitle{Plotting functions}
{\bf All arguments follow exactly Mathematica's ordering,
with a Pythonic naming style.} 
{\dblue Plotting:}
 \begin{verbatim}
   plot(f, xmin, xmin, **kwargs) 
   
   parametric_plot((fx, fy), xmin, xmax, **kwargs)

   polar_plot(f, xmin, xmax, **kwargs) 

   list_plot(L, **kwargs) # L is 1D or 2D list of data
 \end{verbatim}

   f is a single function that returns a float or \\
   can also be a list of functions f=(f1,f2,...,fn).
\end{frame}

%%%

\begin{frame}[fragile]

\frametitle{Graphics Primitives}

{\dblue Graphic primitive objects:}

 \begin{verbatim}
  circle((x, y), radius)

  disk((x, y), radius, (rad1, rad2))

  line(xydata)

  point(xydata) 

  polygon(xydata)

  text(string, (x, y))

 \end{verbatim}
\end{frame}

%%%

\begin{frame}[fragile]

\frametitle{Saving and Showing Graphics Objects}

{\bf With a Graphics object, G you can:}
\begin{verbatim}
  show(G, **kwargs) 
  save(G, **kwargs)
\end{verbatim}
In the notebook {\tt show} and {\tt save} have the same effect,\\
except that with {\tt save} you can specify any path name.\\
\vspace{1ex} 
\vspace{1ex} 
{\bf With an array of graphics objects, GL, you can:}
\begin{verbatim}
  graphics_array(GL, **kwargs)
\end{verbatim}
\vspace{1ex} 
{\dblue Now live examples from the SAGE notebook ...}
\end{frame}

%%%

%\begin{frame}[fragile]
%To avoid re-inventing the wheel, we choose to 
%follow closely Mathematica's plotting functionality:
%while keeping key python conventions (like naming)
%
%\begin{verbatim}
%plot(f, min, max, **kwargs) |  Plot[f,{x,min,max},opts]
%parametric_plot()       | ParametricPlot[]
%polar_plot()        | PolarPlot[]
%contour_plot(f, (xmin, xmax), (ymin, ymax)] | ContourPlot[]
%
%circle((x,y), r, **kwargs) | Circle[{x, y}, r]
%disk((x,y), r, **kwargs) | Disk[{x, y}, r]
%point((x,y), **kwargs)  | Point[{x, y}]
%polygon(pnts, **kwargs) | Polygon[pnts]
%line(pnts,**kwargs)   | Line[pnts]
%
%graphics_array(a, **kwargs) | GraphicsArray[a]
%\end{verbatim}
%\end{frame}

%%%

%\frame
%%{
%\begin{center}
%\begin{figure}[hbp]
%\includegraphics[width=8cm,height=8cm]{zeta}
%\end{figure}
%\end{center}
%}
%

%%%

%
%\frame
%{
%\begin{center}
%\begin{figure}
%\includegraphics[scale=0.50]{one}
%\end{figure}
%\end{center}
%}
%
%
%\frame
%{
%\begin{center}
%\begin{figure}
%\includegraphics[scale=0.70]{one}
%\end{figure}
%\end{center}
%}
%
%\begin{frame}[fragile]
%\begin{semiverbatim}
%{\bc sage:} r = RR(golden_ratio) {\bc # 53 bits of precision}
%{\bc sage:} G = Graphics() {\bc #empty Graphics object}
%
%{\bc sage:} for n in range(1,1000): {\bc #loop adding points}
%    {\bc...:}    xr = n*cos(2*pi*n*r)
%    {\bc...:}    yr = n*sin(2*pi*n*r)
%    {\bc...:}    G += point((xr,yr), rgbcolor=hue(0.4+0.2*(n\%2)))
%
%\end{semiverbatim}
%\end{frame}
%
%\begin{frame}[fragile]
%\begin{semiverbatim}
%{\bc sage:} show(G, axes=False) {\bc #don't draw axes}
%\end{semiverbatim}
%\begin{center}
%\begin{figure}
%\includegraphics[scale=0.75]{spiral}
%\end{figure}
%\end{center}
%
%\end{frame}
%

\end{document}
