day1/session1.tex
changeset 110 220ac08e67b5
parent 107 647239f95c4a
child 113 e7febbccd376
equal deleted inserted replaced
108:324b617ce8cd 110:220ac08e67b5
   131 \begin{verbatim}
   131 \begin{verbatim}
   132   $ ipython -pylab  
   132   $ ipython -pylab  
   133 \end{verbatim}
   133 \end{verbatim}
   134 Exiting
   134 Exiting
   135 \begin{lstlisting}     
   135 \begin{lstlisting}     
   136   In [1]: print "Hello, World!"
   136   In []: print "Hello, World!"
   137   In [2]: ^D
   137   In []: ^D
   138   Do you really want to exit ([y]/n)? y
   138   Do you really want to exit ([y]/n)? y
   139 \end{lstlisting}
   139 \end{lstlisting}
   140 Breaking out of loops
   140 Breaking out of loops
   141 \begin{lstlisting}     
   141 \begin{lstlisting}     
   142   In [1]: while True:
   142   In []: while True:
   143     ...:     print "Hello, World!"
   143     ...:     print "Hello, World!"
   144     ...:     
   144     ...:     
   145   Hello, World!
   145   Hello, World!
   146   Hello, World!^C
   146   Hello, World!^C
   147 \end{lstlisting}
   147 \end{lstlisting}
   148 \end{frame}
   148 \end{frame}
   149 
   149 
   150 \begin{frame}[fragile]
   150 \begin{frame}[fragile]
   151 \frametitle{First Plot}
   151 \frametitle{First Plot}
   152 \begin{lstlisting}
   152 \begin{lstlisting}
   153   In [2]: x = linspace(0, 2*pi, 51)
   153   In []: x = linspace(0, 2*pi, 51)
   154 \end{lstlisting}
   154 \end{lstlisting}
   155 \typ{linspace(start, stop, num)} \\
   155 \typ{linspace(start, stop, num)} \\
   156 returns \typ{num} evenly spaced points, in the interval [\typ{start}, \typ{stop}].
   156 returns \typ{num} evenly spaced points, in the interval [\typ{start}, \typ{stop}].
   157 \begin{lstlisting}
   157 \begin{lstlisting}
   158 
   158 
   159   In [3]: plot(x,sin(x))
   159   In []: plot(x,sin(x))
   160 \end{lstlisting}
   160 \end{lstlisting}
   161 \typ{plot(x, y)}\\
   161 \typ{plot(x, y)}\\
   162 plots \typ{x} and \typ{y} using default line style and color
   162 plots \typ{x} and \typ{y} using default line style and color
   163 \end{frame}
   163 \end{frame}
   164 
   164 
   165 \begin{frame}[fragile]
   165 \begin{frame}[fragile]
   166 \frametitle{Adding Labels}
   166 \frametitle{Adding Labels}
   167   \begin{lstlisting}
   167   \begin{lstlisting}
   168 In [4]: xlabel('x')
   168 In []: xlabel('x')
   169   \end{lstlisting}
   169   \end{lstlisting}
   170 \typ{xlabel(s)} sets the label of the \typ{x}-axis to \typ{s}
   170 \typ{xlabel(s)} sets the label of the \typ{x}-axis to \typ{s}
   171 
   171 
   172   \begin{lstlisting}
   172   \begin{lstlisting}
   173 In [5]: ylabel('sin(x)')
   173 In []: ylabel('sin(x)')
   174   \end{lstlisting}
   174   \end{lstlisting}
   175 \typ{ylabel(s)} sets the label of the \typ{y}-axis to \typ{s}
   175 \typ{ylabel(s)} sets the label of the \typ{y}-axis to \typ{s}
   176 \end{frame}
   176 \end{frame}
   177 
   177 
   178 \begin{frame}[fragile]
   178 \begin{frame}[fragile]
   179 \frametitle{Another example}
   179 \frametitle{Another example}
   180   \begin{lstlisting}
   180   \begin{lstlisting}
   181 In [6]: clf()
   181 In []: clf()
   182 
   182 In []: y = linspace(0, 2*pi, 51)
   183 In [7]: y = linspace(0, 2*pi, 51)
   183 In []: plot(y, -2*sin(-y))
   184 
   184 In []: xlabel('y')
   185 In [8]: plot(y, -2*sin(-y))
   185 In []: ylabel('-2sin(-y)')
   186 
       
   187 In [9]: xlabel('y')
       
   188 
       
   189 In [10]: ylabel('-2sin(-y)')
       
   190   \end{lstlisting}
   186   \end{lstlisting}
   191 \end{frame}
   187 \end{frame}
   192 
   188 
   193 \begin{frame}[fragile]
   189 \begin{frame}[fragile]
   194 \frametitle{Title and Legends}
   190 \frametitle{Title and Legends}
   195 \begin{lstlisting}
   191 \begin{lstlisting}
   196 In [11]: title('Sinusoids')
   192 In []: title('Sinusoids')
   197 
   193 # When plot made with label
   198 In [12]: legend(['-2sin(-y)'])
   194 # plot(y, -2*sin(-y), label='sin')
   199 \end{lstlisting}
   195 In []: legend() 
   200 \end{frame}
   196 # When no label, or to change
       
   197 In []: legend(['sin'])
       
   198 \end{lstlisting}
       
   199 \end{frame}
       
   200 
       
   201 \begin{frame}[fragile]
       
   202 \frametitle{Changing Legend Placement}
       
   203 \begin{lstlisting}
       
   204 In []: legend(['sin'], loc=5) 
       
   205 #or 
       
   206 In []: legend(['sin'], loc='right') 
       
   207 #or
       
   208 In []: legend(['sin'], loc=(x,y)) 
       
   209 #(x,y) is position of lower-left 
       
   210 #corner of legend in the axes co-ords
       
   211 \end{lstlisting}
       
   212 \end{frame}
       
   213 
       
   214 \begin{frame}[fragile]
       
   215 \frametitle{Changing Legend Placement}
       
   216 \vspace{-0.15in}
       
   217 \begin{lstlisting}
       
   218 Location String   Code
       
   219 ===============   ====
       
   220 'best'            0
       
   221 'upper right'     1
       
   222 'upper left'      2
       
   223 'lower left'      3
       
   224 'lower right'     4
       
   225 'right'           5
       
   226 'center left'     6
       
   227 'center right'    7
       
   228 'lower center'    8
       
   229 'upper center'    9
       
   230 'center'          10
       
   231 \end{lstlisting}
       
   232 \end{frame}
       
   233 
   201 
   234 
   202 \begin{frame}[fragile]
   235 \begin{frame}[fragile]
   203 \frametitle{Saving \& Closing}
   236 \frametitle{Saving \& Closing}
   204 \begin{lstlisting}
   237 \begin{lstlisting}
   205 In [13]: savefig('2siny.png')
   238 In []: savefig('sin.png')
   206 
   239 
   207 In [14]: close()
   240 In []: close()
       
   241 \end{lstlisting}
       
   242 \end{frame}
       
   243 
       
   244 \begin{frame}[fragile]
       
   245 \frametitle{Saving \& Closing}
       
   246 \begin{lstlisting}
       
   247 In []: savefig('sin.png')
       
   248 
       
   249 In []: close()
   208 \end{lstlisting}
   250 \end{lstlisting}
   209 \end{frame}
   251 \end{frame}
   210 
   252 
   211 \begin{frame}[fragile]
   253 \begin{frame}[fragile]
   212 \frametitle{Multiple Figures}
   254 \frametitle{Multiple Figures}
   227 In []: plot(y, sin(y), linewidth=2)  
   269 In []: plot(y, sin(y), linewidth=2)  
   228 \end{lstlisting}
   270 \end{lstlisting}
   229 \end{frame}
   271 \end{frame}
   230 
   272 
   231 \begin{frame}[fragile]
   273 \begin{frame}[fragile]
       
   274 \frametitle{Annotating}
       
   275 \begin{lstlisting}
       
   276 In []: annotate('Sample point',
       
   277                 (50,200))
       
   278 \end{lstlisting}
       
   279 \end{frame}
       
   280 
       
   281 \begin{frame}[fragile]
   232 \frametitle{Axes lengths}
   282 \frametitle{Axes lengths}
   233   \begin{lstlisting}
   283   \begin{lstlisting}
   234 #Get the limits
   284 #Get the limits
   235 In []: xmin, xmax = xlim() 
   285 In []: xmin, xmax = xlim() 
   236 In []: ymin, ymax = ylim() 
   286 In []: ymin, ymax = ylim()