day1/cheatsheet1.tex
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 20 Nov 2009 00:05:50 +0530
changeset 319 cef948318842
parent 295 39d7c4e14585
child 307 be62ebb11407
permissions -rwxr-xr-x
Minor edits to sessions 2, 4, 6 on day1.

\documentclass[12pt]{article}


\title{Interactive Plotting}
\author{FOSSEE}
\usepackage{listings}
\lstset{language=Python,
    basicstyle=\ttfamily,
commentstyle=\itshape\bfseries
}
\newcommand{\typ}[1]{\lstinline{#1}}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler}
\usepackage[scaled=.95]{helvet}

\begin{document}
\date{}
\vspace{-1in}
\begin{center}
\LARGE{Interactive Plotting}\\
\large{FOSSEE}
\end{center}
\section{Starting up...}

\begin{lstlisting}
  $ ipython -pylab  
\end{lstlisting}
Exiting 
\begin{lstlisting}     
In [2]: (Ctrl-D)^D
Do you really want to exit ([y]/n)? y
\end{lstlisting}

\section{Plotting}

  \begin{lstlisting}
In [1]: x = linspace(0, 2*pi, 50)
In [2]: plot(x, sin(x))
In [3]: xlabel('x')
In [4]: ylabel('sin(x)')
In [5]: title('Sinusoids')
In [6]: legend(['sin(y)'])
In [7]: legend(['sin(2y)'], loc = 'center')
# loc = 'upper right', 'upper left', 'lower left, 'lower right', 'center left',
#      'center right', 'lower center', 'upper center', 'best', 'right', 'center'

In [8]: legend(['sin(2y)'], loc = (.8, .1))

In [9]: savefig('sin.png')   # Save figure
In [10]: close()             # Closes the figure

In [11]: clf()               # Clears the Plot area

In [12]: plot(y, sin(y), 'g')
# Colors can be: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'

In [13]: plot(y, cos(y), 'r', linewidth=2)

In [14]: legend(['x', '-x'])
In [15]: annotate('origin', xy=(0, 0))

In [16]: xmin, xman = xlim()           # Without arguments gets
In [17]: ymin, ymax = ylim()           # values

In [18]: xlim(0, 2 * pi)               # With values, sets the
In [19]: ylim(ymin - 0.2, ymax + 0.2)  # specified values
  \end{lstlisting}

\section{Saving and running scripts}
\begin{itemize}
  \item \typ{\%hist}
  \item \typ{\%save four\_plot.py 16 18-27}
  \item \typ{\%run -i four\_plot.py}
\end{itemize}

\end{document}