day1/cheatsheet1.tex
author Shantanu <shantanu@fossee.in>
Wed, 18 Nov 2009 12:36:26 +0530
changeset 307 be62ebb11407
parent 295 39d7c4e14585
child 308 d93be08d69f8
permissions -rwxr-xr-x
Added changes for cheat sheet 1.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
\documentclass[12pt]{article}
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     2
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     3
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
\title{Interactive Plotting}
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
\author{FOSSEE}
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     6
\usepackage{listings}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     7
\lstset{language=Python,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     8
    basicstyle=\ttfamily,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
     9
commentstyle=\itshape\bfseries
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    10
}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    11
\newcommand{\typ}[1]{\lstinline{#1}}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    12
\usepackage[english]{babel}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    13
\usepackage[latin1]{inputenc}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    14
\usepackage{times}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    15
\usepackage[T1]{fontenc}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    16
\usepackage{ae,aecompl}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    17
\usepackage{mathpazo,courier,euler}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    18
\usepackage[scaled=.95]{helvet}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    19
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
\begin{document}
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    21
\date{}
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    22
\vspace{-1in}
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    23
\begin{center}
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    24
\LARGE{Interactive Plotting}\\
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    25
\large{FOSSEE}
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    26
\end{center}
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    27
\section{Starting up...}
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    29
\begin{lstlisting}
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
  $ ipython -pylab  
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    31
\end{lstlisting}
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    32
Exiting 
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    33
\begin{lstlisting}     
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    34
In [2]: (Ctrl-D)^D
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    35
Do you really want to exit ([y]/n)? y
307
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    36
\end{lstlisting} %$
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    38
\section{Plotting}
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    39
307
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    40
\subsection{Label}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    41
Pylab accepts TeX equation expressions in any text expression. To get something like:\\
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    42
$\sigma_i=15$ \\
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    43
on title of figure use: 
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    44
\begin{lstlisting}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    45
  title('$\sigma_i=15$')
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    46
\end{lstlisting}  
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    47
Same way one can have TeX expression on xlabel, ylabel etc.
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    48
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    49
\subsection{legends}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    50
Apart from using \kwrd{loc='center'} for positioning the legend, one can also mention explicit co-ordinates for placement. 
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    51
\begin{lstlisting}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    52
In []: legend(['sin(2y)'], loc=(.8,.1)) 
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    53
\end{lstlisting}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    54
\typ{loc = 0, 1} (left top position of graph)\\
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    55
\typ{loc = 0.5, 0.5} (center of graph).
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    56
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    57
%\subsection{Multiple figures}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    58
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    59
\subsection{Saving figures}
be62ebb11407 Added changes for cheat sheet 1.
Shantanu <shantanu@fossee.in>
parents: 295
diff changeset
    60
One can save figure in any of these formats: png, pdf, ps, eps and svg.
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    61
  \begin{lstlisting}
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    62
In [1]: x = linspace(0, 2*pi, 50)
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    63
In [2]: plot(x, sin(x))
264
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    64
In [3]: xlabel('x')
c3a1de5b8216 Updated day1 session1.
Puneeth Chaganti <punchagan@fossee.in>
parents: 107
diff changeset
    65
In [4]: ylabel('sin(x)')
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    66
In [5]: title('Sinusoids')
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    67
In [6]: legend(['sin(y)'])
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    68
In [7]: legend(['sin(2y)'], loc = 'center')
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    69
# loc = 'upper right', 'upper left', 'lower left, 'lower right', 'center left',
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    70
#      'center right', 'lower center', 'upper center', 'best', 'right', 'center'
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    71
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    72
In [8]: legend(['sin(2y)'], loc = (.8, .1))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    73
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    74
In [9]: savefig('sin.png')   # Save figure
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    75
In [10]: close()             # Closes the figure
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    76
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    77
In [11]: clf()               # Clears the Plot area
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    78
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    79
In [12]: plot(y, sin(y), 'g')
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    80
# Colors can be: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    81
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    82
In [13]: plot(y, cos(y), 'r', linewidth=2)
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    83
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    84
In [14]: legend(['x', '-x'])
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    85
In [15]: annotate('origin', xy=(0, 0))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    86
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    87
In [16]: xmin, xman = xlim()           # Without arguments gets
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    88
In [17]: ymin, ymax = ylim()           # values
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    89
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    90
In [18]: xlim(0, 2 * pi)               # With values, sets the
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    91
In [19]: ylim(ymin - 0.2, ymax + 0.2)  # specified values
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    92
  \end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    93
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    94
\section{Saving and running scripts}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    95
\begin{itemize}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    96
  \item \typ{\%hist}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    97
  \item \typ{\%save four\_plot.py 16 18-27}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    98
  \item \typ{\%run -i four\_plot.py}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
    99
\end{itemize}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 264
diff changeset
   100
107
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   101
\end{document}
647239f95c4a Added rough draft of slides and cheatsheet for Interactive Plotting.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   102