day1/cheatsheet2.tex
author Santosh G. Vattam <vattam.santosh@gmail.com>
Wed, 18 Nov 2009 17:07:19 +0530
changeset 309 0b1f2c378d84
parent 300 f87f2a310abe
child 311 5303c34a3180
permissions -rwxr-xr-x
Minor changes on cheatsheet of 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}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    32
In [1]: x = [0, 1, 2, 3]
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    33
In [2]: y = [7, 11, 15, 19]
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    34
In [3]: plot(x, y)
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    35
In [4]: clf()
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    36
In [5]: plot(x, y, 'o')  # Plotting Circles
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}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    44
In [10]: mtlist = []      # Empty List
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    45
In [11]: lst = [ 1, 2, 3, 4, 5] 
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}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    49
In [12]: lst[1:3]         # A slice.
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    50
Out[12]: [2, 3]
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    51
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    52
In [13]: lst[1:-1]
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    53
Out[13]: [2, 3, 4]
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}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    57
In [14]: a = [ 6, 7, 8, 9]
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    58
In [15]: b = lst + a
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    59
In [16]: b
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    60
Out[16]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
295
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    62
In [17]: lst.append(6)
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    63
In [18]: lst
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    64
Out[18]: [ 1, 2, 3, 4, 5, 6]
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
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    67
Iterating over a List
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    68
\begin{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    69
In [19]: for each in b:  # Iterating over the list, element-wise
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    70
 ....:     print b       # Print each element
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    71
 ....:
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    72
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    73
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    74
Splitting Strings
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    75
\begin{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    76
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
    77
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
    78
Out[21]: ['1.2000e-01', '7.4252e-01']
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    79
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    80
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    81
Plotting from Files
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    82
\begin{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    83
In [22]: L = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    84
In [23]: T = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    85
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    86
#Open a file & operate on each line
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    87
In [24]: for line in open('pendulum.txt'):  
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    88
  ....     point = line.split()
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    89
  ....     L.append(float(point[0]))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    90
  ....     T.append(float(point[1]))
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    91
In [25]: TSq = []
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    92
In [26]: for t in T:
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93
 ....:     TSq.append(t*t)
295
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
 ....:     
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    96
In [27]: plot(L, TSq, '.')
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    97
\end{lstlisting}
39d7c4e14585 Added all day 1 cheatsheets.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 284
diff changeset
    98
284
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    99
\end{document}
3c191accbb32 Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   100