day1/cheatsheet2.tex
author Santosh G. Vattam <vattam.santosh@gmail.com>
Wed, 18 Nov 2009 17:14:33 +0530
changeset 311 5303c34a3180
parent 309 0b1f2c378d84
child 313 f5bcb974a665
permissions -rwxr-xr-x
Minor edits to cheatsheet session 2 day 1.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
284
3c191accbb32 Added Cheatsheets for day1.
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: 284
diff changeset
     2
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     3
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     4
\title{Plotting Points}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     5
\author{FOSSEE}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     6
\usepackage{listings}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     7
\lstset{language=Python,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     8
    basicstyle=\ttfamily,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
     9
  commentstyle=\itshape\bfseries,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    10
  showstringspaces=false,
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    11
}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    12
\newcommand{\typ}[1]{\lstinline{#1}}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    13
\usepackage[english]{babel}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    14
\usepackage[latin1]{inputenc}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    15
\usepackage{times}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    16
\usepackage[T1]{fontenc}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    17
\usepackage{ae,aecompl}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    18
\usepackage{mathpazo,courier,euler}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    19
\usepackage[scaled=.95]{helvet}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    20
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
\begin{document}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
\date{}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
\vspace{-1in}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
\begin{center}
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    25
\LARGE{Plotting Points}\\
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
\large{FOSSEE}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
\end{center}
309
0b1f2c378d84 Minor changes on cheatsheet of session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 300
diff changeset
    28
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    29
\section{Plotting Points with Lists}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    30
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    31
\begin{lstlisting}
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    32
In []: x = [0, 1, 2, 3]
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    33
In []: y = [7, 11, 15, 19]
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    34
In []: plot(x, y)
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    35
In []: clf()
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    36
In []: plot(x, y, 'o')  # Plotting Circles
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    37
#Dots - '.', #Dashed lines - '--' #Lines - '-'
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    38
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    39
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    40
\section{Lists}
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    42
Initializing
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    43
  \begin{lstlisting}
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    44
In []: mtlist = []      # Empty List
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    45
In []: lst = [ 1, 2, 3, 4, 5] 
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    46
  \end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    47
Slicing
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    48
\begin{lstlisting}
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    49
In []: lst[1:3]         # A slice.
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    50
Out[]: [2, 3]
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    51
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    52
In []: lst[1:-1]
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    53
Out[]: [2, 3, 4]
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    54
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    55
Appending to lists
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    56
\begin{lstlisting}
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    57
In []: a = [ 6, 7, 8, 9]
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    58
In []: b = lst + a
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    59
In []: b
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    60
Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    62
In []: lst.append(6)
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    63
In []: lst
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    64
Out[]: [ 1, 2, 3, 4, 5, 6]
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    65
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    66
Iterating over a List
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    67
\begin{lstlisting}
311
5303c34a3180 Minor edits to cheatsheet session 2 day 1.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 309
diff changeset
    68
In []: for each in b:  # Iterating over the list, element-wise
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    69
 ....:     print b       # Print each element
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    70
 ....:
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    71
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    72
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    73
Splitting Strings
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    74
\begin{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    75
In [20]: line = '1.2000e-01 7.4252e-01'
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    76
In [21]: point = line.split()    # Splits the string at the space
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    77
Out[21]: ['1.2000e-01', '7.4252e-01']
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    78
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    79
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    80
Plotting from Files
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    81
\begin{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    82
In [22]: L = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    83
In [23]: T = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    84
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    85
#Open a file & operate on each line
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    86
In [24]: for line in open('pendulum.txt'):  
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    87
  ....     point = line.split()
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    88
  ....     L.append(float(point[0]))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    89
  ....     T.append(float(point[1]))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    90
In [25]: TSq = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    91
In [26]: for t in T:
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    92
 ....:     TSq.append(t*t)
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    93
 ....:     
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    94
 ....:     
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    95
In [27]: plot(L, TSq, '.')
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    96
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    97
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    98
\end{document}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    99