day1/session1.tex
changeset 140 fe6a38572a65
parent 138 5365aa8ec9a5
child 141 fccf675946bf
equal deleted inserted replaced
139:039a07b0ff53 140:fe6a38572a65
   123 %% \end{frame}
   123 %% \end{frame}
   124 
   124 
   125 
   125 
   126 \begin{frame}[fragile]
   126 \begin{frame}[fragile]
   127 \frametitle{Starting up...}
   127 \frametitle{Starting up...}
       
   128 \begin{block}{}
   128 \begin{verbatim}
   129 \begin{verbatim}
   129   $ ipython -pylab  
   130   $ ipython -pylab  
   130 \end{verbatim}
   131 \end{verbatim}
       
   132 \end{block}
       
   133 \begin{lstlisting}     
       
   134   In []: print "Hello, World!"
       
   135   Hello, World!
       
   136 \end{lstlisting}
   131 Exiting
   137 Exiting
   132 \begin{lstlisting}     
   138 \begin{lstlisting}     
   133   In []: print "Hello, World!"
   139   In []: ^D(Ctrl-D)
   134   In []: ^D
   140   Do you really want to exit([y]/n)? y
   135   Do you really want to exit ([y]/n)? y
   141 \end{lstlisting}
   136 \end{lstlisting}
   142 \end{frame}
       
   143 
       
   144 \begin{frame}[fragile]
       
   145 \frametitle{Loops}
   137 Breaking out of loops
   146 Breaking out of loops
   138 \begin{lstlisting}     
   147 \begin{lstlisting}     
   139   In []: while True:
   148   In []: while True:
   140     ...:     print "Hello, World!"
   149     ...:     print "Hello, World!"
   141     ...:     
   150     ...:     
   142   Hello, World!
   151   Hello, World!
   143   Hello, World!^C
   152   Hello, World!^C(Ctrl-C)
   144 \end{lstlisting}
   153 \end{lstlisting}
   145 \end{frame}
   154 \end{frame}
   146 
   155 
   147 \begin{frame}[fragile]
   156 \begin{frame}[fragile]
   148 \frametitle{First Plot}
   157 \frametitle{First Plot}
   149 \begin{lstlisting}
   158 \begin{columns}
   150   In []: x = linspace(0, 2*pi, 51)
   159     \column{0.25\textwidth}
   151 \end{lstlisting}
   160     \hspace*{-0.5in}
   152 \typ{linspace(start, stop, num)} \\
   161   \includegraphics[height=2in, interpolate=true]{data/firstplot}  
       
   162     \column{0.7\textwidth}
       
   163     \begin{block}{Code}
       
   164     \small
       
   165 \begin{lstlisting}
       
   166 In []: x=linspace(0,2*pi,51)
       
   167 In []: plot(x,sin(x))
       
   168 \end{lstlisting}
       
   169     \small
       
   170     \end{block}
       
   171 \end{columns}
       
   172 \end{frame}
       
   173 
       
   174 
       
   175 \begin{frame}[fragile]
       
   176 \frametitle{Walkthrough}
       
   177 \begin{block}{\typ{linspace(start, stop, num)} }
   153 returns \typ{num} evenly spaced points, in the interval [\typ{start}, \typ{stop}].
   178 returns \typ{num} evenly spaced points, in the interval [\typ{start}, \typ{stop}].
   154 \begin{lstlisting}
   179 \end{block}
   155 
   180 \vspace*{.5in}
   156   In []: plot(x,sin(x))
   181 \begin{block}{\typ{plot(x, y)}}
   157 \end{lstlisting}
       
   158 \typ{plot(x, y)}\\
       
   159 plots \typ{x} and \typ{y} using default line style and color
   182 plots \typ{x} and \typ{y} using default line style and color
       
   183 \end{block}
   160 \end{frame}
   184 \end{frame}
   161 
   185 
   162 \begin{frame}[fragile]
   186 \begin{frame}[fragile]
   163 \frametitle{Adding Labels}
   187 \frametitle{Adding Labels}
       
   188 \begin{columns}
       
   189   \column{0.25\textwidth}
       
   190   \hspace*{-0.45in}
       
   191   \includegraphics[height=2in, interpolate=true]{data/label}  
       
   192   \hspace*{0.5in}
       
   193   \column{0.55\textwidth}
       
   194   \begin{block}{}
       
   195   \small
   164   \begin{lstlisting}
   196   \begin{lstlisting}
   165 In []: xlabel('x')
   197 In []: xlabel('x')
   166   \end{lstlisting}
   198 
   167 \typ{xlabel(s)} sets the label of the \typ{x}-axis to \typ{s}
       
   168 
       
   169   \begin{lstlisting}
       
   170 In []: ylabel('sin(x)')
   199 In []: ylabel('sin(x)')
   171   \end{lstlisting}
   200   \end{lstlisting}
   172 \typ{ylabel(s)} sets the label of the \typ{y}-axis to \typ{s}
   201   \small
       
   202 %  \end{lstlisting}
       
   203 %\typ{xlabel(s)} sets the label of the \typ{x}-axis to \typ{s}
       
   204 
       
   205 %  \begin{lstlisting}
       
   206   \end{block}
       
   207 %\typ{ylabel(s)} sets the label of the \typ{y}-axis to \typ{s}
       
   208 \end{columns}
   173 \end{frame}
   209 \end{frame}
   174 
   210 
   175 \begin{frame}[fragile]
   211 \begin{frame}[fragile]
   176 \frametitle{Another example}
   212 \frametitle{Another example}
   177   \begin{lstlisting}
   213   \begin{lstlisting}
   178 In []: clf()
   214 In []: clf()
   179 In []: y = linspace(0, 2*pi, 51)
   215 In []: y = linspace(0, 2*pi, 51)
   180 In []: plot(y, -2*sin(-y))
   216 In []: plot(y, sin(2*y))
   181 In []: xlabel('y')
   217 In []: xlabel('y')
   182 In []: ylabel('-2sin(-y)')
   218 In []: ylabel('sin(2y)')
   183   \end{lstlisting}
   219   \end{lstlisting}
   184 \end{frame}
   220 \end{frame}
   185 
   221 
   186 \begin{frame}[fragile]
   222 \begin{frame}[fragile]
   187 \frametitle{Title and Legends}
   223 \frametitle{Title and Legends}
       
   224 \vspace*{-0.15in}
       
   225 %  \begin{block}{}
       
   226 %  \small
   188 \begin{lstlisting}
   227 \begin{lstlisting}
   189 In []: title('Sinusoids')
   228 In []: title('Sinusoids')
   190 #Sets the title of the figure
   229 #Sets the title of the figure
   191 
   230 In []: legend(['sin(2y)'])
   192 In []: legend() 
   231 # When no label, or to change
   193 # Shows a legend in the figure
   232 \end{lstlisting}
   194 # Used when plot was made with label
   233 %  \small
   195 # plot(y, -2*sin(-y), label='sin')
   234 %  \end{block}
   196 In []: legend(['sin'])
   235   \vspace*{-0.1in}
   197 # When no labels were used
   236   \begin{center}
   198 # Or to change the labels
   237   \includegraphics[height=2in, interpolate=true]{data/legend}  
   199 
   238   \end{center}
   200 \end{lstlisting}
       
   201 \end{frame}
   239 \end{frame}
   202 
   240 
   203 \begin{frame}[fragile]
   241 \begin{frame}[fragile]
   204 \frametitle{Changing Legend Placement}
   242 \frametitle{Changing Legend Placement}
   205 \begin{lstlisting}
   243 \vspace*{-0.1in}
   206 In []: legend(['sin'], loc=5) 
   244 \begin{lstlisting}
   207 #or 
   245 In []: legend(['sin(2y)'], loc=(0.75,0.1)) 
   208 In []: legend(['sin'], loc='right') 
       
   209 #or
       
   210 In []: legend(['sin'], loc=(x,y)) 
       
   211 #(x,y) is position of lower-left 
   246 #(x,y) is position of lower-left 
   212 #corner of legend in the axes co-ords
   247 #corner of legend.
   213 \end{lstlisting}
   248 \end{lstlisting}
       
   249 %\vspace*{-0.2in}
       
   250 \begin{center}
       
   251   \includegraphics[height=2in, interpolate=true]{data/loc}  
       
   252 \end{center}
   214 \end{frame}
   253 \end{frame}
   215 
   254 
   216 \begin{frame}[fragile]
   255 \begin{frame}[fragile]
   217 \frametitle{Changing Legend Placement}
   256 \frametitle{Changing Legend Placement}
   218 \vspace{-0.15in}
   257 \begin{columns}
   219 \begin{lstlisting}
   258     \column{0.6\textwidth}
   220 Location String   Code
   259 \begin{block}{}
   221 ===============   ====
   260     \small
   222 'best'            0
   261 \begin{lstlisting}
   223 'upper right'     1
   262 In []: legend(['sin(2y)'], 
   224 'upper left'      2
   263          loc='right')
   225 'lower left'      3
   264 \end{lstlisting}
   226 'lower right'     4
   265     \small
   227 'right'           5
   266 \end{block}
   228 'center left'     6
   267 \column{0.45\textwidth}
   229 'center right'    7
   268 \vspace{-0.2in}
   230 'lower center'    8
   269 \begin{lstlisting}
   231 'upper center'    9
   270 Location String   
   232 'center'          10
   271 ===============   
   233 \end{lstlisting}
   272 'best'            
       
   273 'upper right'     
       
   274 'upper left'      
       
   275 'lower left'      
       
   276 'lower right'     
       
   277 'right'           
       
   278 'center left'     
       
   279 'center right'    
       
   280 'lower center'    
       
   281 'upper center'    
       
   282 'center'          
       
   283 \end{lstlisting}
       
   284 \end{columns}
   234 \end{frame}
   285 \end{frame}
   235 
   286 
   236 
   287 
   237 \begin{frame}[fragile]
   288 \begin{frame}[fragile]
   238 \frametitle{Saving \& Closing}
   289 \frametitle{Saving \& Closing}
   249 In []: figure(1)
   300 In []: figure(1)
   250 In []: plot(x, sin(x))
   301 In []: plot(x, sin(x))
   251 In []: figure(2)
   302 In []: figure(2)
   252 In []: plot(x, cos(x))
   303 In []: plot(x, cos(x))
   253 In []: figure(1)
   304 In []: figure(1)
   254 In []: title('sin(x)'))
   305 In []: title('sin(x)')
   255 \end{lstlisting}
   306 \end{lstlisting}
   256 \end{frame}
   307 \end{frame}
   257 
   308 
   258 \begin{frame}[fragile]
   309 \begin{frame}[fragile]
   259 \frametitle{Showing it better}
   310 \frametitle{Showing it better}
       
   311 \vspace{-0.15in}
   260 \begin{lstlisting}
   312 \begin{lstlisting}
   261 In []: plot(y, sin(y), 'g')
   313 In []: plot(y, sin(y), 'g')
   262 # plots the curve using green color
   314 # plots the curve using green color
   263 
   315 
   264 In []: plot(y, sin(y), linewidth=2)
   316 In []: plot(y, sin(y), linewidth=2)
   265 # sets the linewidth to 2  
   317 # sets the linewidth to 2  
   266 \end{lstlisting}
   318 \end{lstlisting}
       
   319 \vspace*{-0.2in}
       
   320 \begin{center}
       
   321   \includegraphics[height=2in, interpolate=true]{data/green}  
       
   322 \end{center}
   267 \end{frame}
   323 \end{frame}
   268 
   324 
   269 \begin{frame}[fragile]
   325 \begin{frame}[fragile]
   270 \frametitle{Annotating}
   326 \frametitle{Annotating}
   271 \begin{lstlisting}
   327 \vspace*{-0.15in}
   272 In []: annotate('Sample point',
   328 \begin{lstlisting}
   273                 (50,200))
   329 In []: annotate('local max', 
   274 # Adds the note 'Sample point' at 
   330        xy=(2, 1), 
   275 # the point (50, 200)
   331        xytext=(3, 1.5),
   276 \end{lstlisting}
   332        arrowprops=dict(
       
   333        shrink=0.05),)
       
   334 \end{lstlisting}
       
   335 \vspace*{-0.2in}
       
   336 \begin{center}
       
   337   \includegraphics[height=2in, interpolate=true]{data/annotate}  
       
   338 \end{center}
   277 \end{frame}
   339 \end{frame}
   278 
   340 
   279 \begin{frame}[fragile]
   341 \begin{frame}[fragile]
   280 \frametitle{Axes lengths}
   342 \frametitle{Axes lengths}
   281   \begin{lstlisting}
   343   \begin{lstlisting}
   282 #Get the axes limits
   344 #Get the axes limits
   283 In []: xmin, xmax = xlim() 
   345 In []: xmin, xmax = xlim() 
   284 In []: ymin, ymax = ylim() 
   346 In []: ymin, ymax = ylim() 
   285 
   347 
   286 #Set the axes limits
   348 #Set the axes limits
   287 In []: xlim( xmin, xmax ) 
   349 In []: xlim(xmin, xmax) 
   288 In []: ylim( ymin, ymax ) 
   350 In []: ylim(ymin, ymax) 
   289   \end{lstlisting}
   351   \end{lstlisting}
   290 \end{frame}
   352 \end{frame}
   291 
   353 
   292 \begin{frame}[fragile]
   354 \begin{frame}[fragile]
   293   \begin{center}
   355   \begin{center}
   295   \alert{Don't Close \typ{IPython}}
   357   \alert{Don't Close \typ{IPython}}
   296   \end{center}
   358   \end{center}
   297 \end{frame}
   359 \end{frame}
   298 
   360 
   299 \end{document}
   361 \end{document}
       
   362