Minor edits to cheatsheet session 2 day 1.
\documentclass[12pt]{article}
\title{Plotting Points}
\author{FOSSEE}
\usepackage{listings}
\lstset{language=Python,
basicstyle=\ttfamily,
commentstyle=\itshape\bfseries,
showstringspaces=false,
}
\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{Plotting Points}\\
\large{FOSSEE}
\end{center}
\section{Plotting Points with Lists}
\begin{lstlisting}
In []: x = [0, 1, 2, 3]
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}
\section{Lists}
Initializing
\begin{lstlisting}
In []: mtlist = [] # Empty List
In []: lst = [ 1, 2, 3, 4, 5]
\end{lstlisting}
Slicing
\begin{lstlisting}
In []: lst[1:3] # A slice.
Out[]: [2, 3]
In []: lst[1:-1]
Out[]: [2, 3, 4]
\end{lstlisting}
Appending to lists
\begin{lstlisting}
In []: a = [ 6, 7, 8, 9]
In []: b = lst + a
In []: b
Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In []: lst.append(6)
In []: lst
Out[]: [ 1, 2, 3, 4, 5, 6]
\end{lstlisting}
Iterating over a List
\begin{lstlisting}
In []: for each in b: # Iterating over the list, element-wise
....: print b # Print each element
....:
\end{lstlisting}
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']
\end{lstlisting}
Plotting from Files
\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, '.')
\end{lstlisting}
\end{document}