Added changes for cheat sheet 1.
\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}
\subsection{Label}
Pylab accepts TeX equation expressions in any text expression. To get something like:\\
$\sigma_i=15$ \\
on title of figure use:
\begin{lstlisting}
title('$\sigma_i=15$')
\end{lstlisting}
Same way one can have TeX expression on xlabel, ylabel etc.
\subsection{legends}
Apart from using \kwrd{loc='center'} for positioning the legend, one can also mention explicit co-ordinates for placement.
\begin{lstlisting}
In []: legend(['sin(2y)'], loc=(.8,.1))
\end{lstlisting}
\typ{loc = 0, 1} (left top position of graph)\\
\typ{loc = 0.5, 0.5} (center of graph).
%\subsection{Multiple figures}
\subsection{Saving figures}
One can save figure in any of these formats: png, pdf, ps, eps and svg.
\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}