summaryrefslogtreecommitdiff
path: root/day1/cheatsheet2.tex
diff options
context:
space:
mode:
authorShantanu Choudhary2009-11-18 18:37:15 +0530
committerShantanu Choudhary2009-11-18 18:37:15 +0530
commit18aa4358f52184a2ce398b697f3a03e80fab7708 (patch)
tree6adf70ab82d32c2a88dc24285a4a4e49c9af6c7b /day1/cheatsheet2.tex
parent75c76d5bdd18ce5aeb2ebedda948cad8e720c8c6 (diff)
downloadworkshops-18aa4358f52184a2ce398b697f3a03e80fab7708.tar.gz
workshops-18aa4358f52184a2ce398b697f3a03e80fab7708.tar.bz2
workshops-18aa4358f52184a2ce398b697f3a03e80fab7708.zip
Initial changes to cheat sheet for session 2.
Diffstat (limited to 'day1/cheatsheet2.tex')
-rwxr-xr-xday1/cheatsheet2.tex100
1 files changed, 76 insertions, 24 deletions
diff --git a/day1/cheatsheet2.tex b/day1/cheatsheet2.tex
index c80db4f..a29d436 100755
--- a/day1/cheatsheet2.tex
+++ b/day1/cheatsheet2.tex
@@ -34,9 +34,50 @@ In []: y = [7, 11, 15, 19]
In []: plot(x, y)
In []: clf()
In []: plot(x, y, 'o') # Plotting Circles
-#Dots - '.', #Dashed lines - '--' #Lines - '-'
\end{lstlisting}
+\subsection{Line style/marker}
+\begin{lstlisting}
+The following format string characters are accepted
+to control the line style or marker:
+
+ ================ ===============================
+ character description
+ ================ ===============================
+ '-' solid line style
+ '--' dashed line style
+ '-.' dash-dot line style
+ ':' dotted line style
+ '.' point marker
+ ',' pixel marker
+ 'o' circle marker
+ 'v' triangle_down marker
+ '^' triangle_up marker
+ '<' triangle_left marker
+ '>' triangle_right marker
+ '1' tri_down marker
+ '2' tri_up marker
+ '3' tri_left marker
+ '4' tri_right marker
+ 's' square marker
+ 'p' pentagon marker
+ '*' star marker
+ 'h' hexagon1 marker
+ 'H' hexagon2 marker
+ '+' plus marker
+ 'x' x marker
+ 'D' diamond marker
+ 'd' thin_diamond marker
+ '|' vline marker
+ '_' hline marker
+ ================ ===============================
+
+\end{lstlisting}
+
+\subsection{Marker combinations}
+\typ{In []: plot(x, y, 'ro')} \\
+This plots figure with red colored filled circles.\\
+Similarly other combination of colors and marker can be used.
\section{Lists}
Initializing
@@ -52,7 +93,7 @@ Out[]: [2, 3]
In []: lst[1:-1]
Out[]: [2, 3, 4]
\end{lstlisting}
-Appending to lists
+\subsection{Appending to lists}
\begin{lstlisting}
In []: a = [ 6, 7, 8, 9]
In []: b = lst + a
@@ -63,36 +104,47 @@ In []: lst.append(6)
In []: lst
Out[]: [ 1, 2, 3, 4, 5, 6]
\end{lstlisting}
-Iterating over a List
+\subsection{Iterating over a List}
\begin{lstlisting}
-In []: for each in b: # Iterating over the list, element-wise
- ....: print b # Print each element
+In []: for element in b: # Iterating over the list, element-wise
+ ....: print element # Print each element
....:
\end{lstlisting}
-Splitting Strings
+\section{Strings}
+\subsection{Splitting Strings}
\begin{lstlisting}
-In [20]: line = '1.2000e-01 7.4252e-01'
-In [21]: point = line.split() # Splits the string at the space
-Out[21]: ['1.2000e-01', '7.4252e-01']
+In []: greet = ``hello world''
+In []: print greet.split()
+Out[]: ['hello', 'world']
+In []: greet = ``hello, world''
+In []: print greet.split(',')
+Out[]: ['hello', ' world'] # Note the whitespace before 'world'
\end{lstlisting}
+A string can be split based on the delimiter specified within quotes. A combination of more than one delimiter can also be used.\\
+\typ{In []: greet.split(', ')}\\
+\typ{Out[]: ['hello', 'world']}\\Note the whitespace is not there anymore.
-Plotting from Files
+\section{Plotting from Files}
+\subsection{Opening, reading and writing files}
+
+\begin{lstlisting}
+ In []: f = open('datafile.txt') #By default opens in read mode. If file does not exist then it throws an exception
+ In []: f = open('datafile.txt','r') #Specifying the read mode
+ In []: f = open('datafile.txt', 'w') #Opens the file in write mode. If the file already exists, then it deletes all the previous content and opens.
+\end{lstlisting}
+\subsection{Plotting}
\begin{lstlisting}
-In [22]: L = []
-In [23]: T = []
-
-#Open a file & operate on each line
-In [24]: for line in open('pendulum.txt'):
- .... point = line.split()
- .... L.append(float(point[0]))
- .... T.append(float(point[1]))
-In [25]: TSq = []
-In [26]: for t in T:
- ....: TSq.append(t*t)
- ....:
- ....:
-In [27]: plot(L, TSq, '.')
+l = []
+t = []
+for line in open('pendulum.txt'):
+ point = line.split()
+ l.append(float(point[0]))
+ t.append(float(point[1]))
+tsq = []
+for time in t:
+ tsq.append(time*time)
+plot(l, tsq, '.')
\end{lstlisting}
\end{document}