day2/3Dplotting.tex
changeset 171 29c0c504750c
parent 154 66b117b7edc7
equal deleted inserted replaced
170:36ed5cdf5fde 171:29c0c504750c
   154     \begin{center}
   154     \begin{center}
   155     Visual representation of data
   155     Visual representation of data
   156     \end{center}
   156     \end{center}
   157 \end{frame}
   157 \end{frame}
   158 
   158 
       
   159 
       
   160 \begin{frame}
       
   161     \frametitle{Is this new?}    
       
   162     \begin{center}
       
   163     We have moved from:
       
   164     \end{center}
       
   165     \begin{columns}
       
   166     \column{}
       
   167     \hspace*{-1in}    
       
   168     \includegraphics[width=1.75in,height=1.75in, interpolate=true]{data/3832}      
       
   169     \column{}\hspace*{-0.25in}
       
   170     To
       
   171     \column{}
       
   172     \hspace*{-1in}
       
   173     \includegraphics[width=1.75in, height=1.75in, interpolate=true]{data/torus}  
       
   174     \end{columns}
       
   175 \end{frame}
       
   176 
   159 \begin{frame}
   177 \begin{frame}
   160     \frametitle{3D visualization}
   178     \frametitle{3D visualization}
   161     \Large
   179     \Large
   162     \begin{center}
   180     \begin{center}
   163         Harder but important
   181         Harder but important
   187         Demo of data
   205         Demo of data
   188     \end{center}
   206     \end{center}
   189 \inctime{10}
   207 \inctime{10}
   190 \end{frame}
   208 \end{frame}
   191 
   209 
   192 \section{Tools at your disposal}
   210 \section{Tools available}
       
   211 
       
   212 \subsection{mlab}
       
   213 
       
   214 \begin{frame}
       
   215     {Overview}
       
   216     \Large
       
   217     \begin{itemize}
       
   218         \item Simple
       
   219         \item Convenient
       
   220         \item Full-featured
       
   221     \end{itemize}
       
   222 \end{frame}
       
   223 
       
   224 \begin{frame}[fragile]
       
   225 
       
   226     \frametitle{Getting started}
       
   227     \myemph{\Large Vanilla:}
       
   228     \begin{lstlisting}[language=bash]
       
   229         $ ipython -wthread
       
   230     \end{lstlisting}
       
   231     \myemph{\Large with Pylab:}
       
   232     \begin{lstlisting}[language=bash]
       
   233         $ ipython -pylab -wthread
       
   234     \end{lstlisting}
       
   235 \end{frame}
       
   236 
       
   237 \begin{frame}[fragile]
       
   238     \frametitle{Using mlab}
       
   239 
       
   240     \begin{lstlisting}
       
   241 >>> from enthought.mayavi import mlab
       
   242     \end{lstlisting}
       
   243 
       
   244     \vspace*{0.5in}
       
   245 
       
   246     \myemph{\Large Try these}
       
   247 
       
   248     \vspace*{0.25in}
       
   249 
       
   250     \begin{lstlisting}
       
   251 >>> mlab.test_<TAB>
       
   252 >>> mlab.test_contour3d()
       
   253 >>> mlab.test_contour3d??
       
   254     \end{lstlisting}
       
   255 \end{frame}
       
   256 
       
   257 \begin{frame}
       
   258     {Exploring the view}
       
   259     \begin{columns}
       
   260         \column{0.6\textwidth}
       
   261     \pgfimage[width=3in]{MEDIA/m2/contour3d}
       
   262         \column{0.4\textwidth}
       
   263         \begin{itemize}
       
   264             \item Mouse
       
   265             \item Keyboard
       
   266             \item Toolbar
       
   267             \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon}
       
   268         \end{itemize}
       
   269     \end{columns}
       
   270 \end{frame}
       
   271 
       
   272 \begin{frame}[fragile]
       
   273     \frametitle{plotting 3-D Surface: $x^2+y^2-z^2=1$}
       
   274     \begin{lstlisting}
       
   275 u,v = mgrid[-2:2:100j, -pi:pi:100j]
       
   276 x=sqrt(u*u+1)*cos(v)
       
   277 y=sqrt(u*u+1)*sin(v)
       
   278 z=u
       
   279 mlab.mesh(x,y,z)
       
   280     \end{lstlisting}
       
   281 \begin{figure}
       
   282 \includegraphics[width=1in, height=1in, interpolate=true]{data/hyperboloid}
       
   283 \end{figure}
       
   284 \end{frame}
       
   285 
       
   286 \begin{frame}[fragile]
       
   287     \frametitle{mgrid}    
       
   288     \begin{itemize}
       
   289       \item Creates a multidimensional ``meshgrid''
       
   290       
       
   291       \item In this particular case, creates 2 2D arrays: u,v.
       
   292     \end{itemize}      
       
   293     \begin{lstlisting}
       
   294 In []: mgrid[0:3,0:3]
       
   295 Out[]: 
       
   296 array([[[0, 0, 0],
       
   297         [1, 1, 1],
       
   298         [2, 2, 2]],
       
   299 
       
   300        [[0, 1, 2],
       
   301         [0, 1, 2],
       
   302         [0, 1, 2]]])
       
   303     \end{lstlisting}    
       
   304 \end{frame}
       
   305 
       
   306 \begin{frame}[fragile]
       
   307     \frametitle{mesh}
       
   308       \begin{itemize}
       
   309         \item Plots a surface from data supplied as 2D arrays.
       
   310       \end{itemize}      
       
   311 \end{frame}
       
   312 
       
   313 \begin{frame}[fragile]
       
   314     \frametitle{\mlab\ plotting functions}
       
   315     \begin{columns}
       
   316         \column{0.25\textwidth}
       
   317         \myemph{Points in 3D space}
       
   318         \column{0.5\textwidth}
       
   319     \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex}
       
   320     \end{columns}
       
   321 
       
   322     \begin{lstlisting}
       
   323 >>> from numpy import *
       
   324 >>> t = linspace(0, 2*pi, 50)
       
   325 >>> u = cos(t)*pi
       
   326 >>> x, y, z = sin(u), cos(u), sin(t)
       
   327     \end{lstlisting}
       
   328     \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}}
       
   329 \end{frame}
       
   330 
       
   331 \begin{frame}
       
   332   \begin{columns}
       
   333         \column{0.25\textwidth}
       
   334         \myemph{Connected points in 3D space}
       
   335         \column{0.5\textwidth}
       
   336         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   337   \end{columns}
       
   338   \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}}
       
   339 
       
   340     Plots lines between the points
       
   341     
       
   342 \end{frame}
       
   343 
       
   344 \begin{frame}[fragile]
       
   345     \begin{columns}
       
   346         \column{0.25\textwidth}
       
   347         \myemph{\Large 2D data}
       
   348         \column{0.5\textwidth}
       
   349         \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex}
       
   350     \end{columns}            
       
   351     \begin{lstlisting}
       
   352 >>> x, y = mgrid[-3:3:100j,-3:3:100j]
       
   353 >>> z = sin(x*x + y*y)
       
   354     \end{lstlisting}
       
   355 
       
   356     \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}}
       
   357 
       
   358     \alert{Assumes the points are rectilinear}
       
   359 
       
   360 \end{frame}
       
   361 
       
   362 \begin{frame}[fragile]
       
   363     \myemph{\Large 2D data: \texttt{mlab.mesh}}
       
   364     \vspace*{0.25in}
       
   365 
       
   366     \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}}
       
   367 
       
   368     \alert{Points needn't be regular}
       
   369 
       
   370     \vspace*{0.25in}
       
   371 \begin{lstlisting}
       
   372 >>> phi, theta = numpy.mgrid[0:pi:20j, 
       
   373 ...                         0:2*pi:20j]
       
   374 >>> x = sin(phi)*cos(theta)
       
   375 >>> y = sin(phi)*sin(theta)
       
   376 >>> z = cos(phi)
       
   377 >>> mlab.mesh(x, y, z, 
       
   378 ...           representation=
       
   379 ...           'wireframe')
       
   380 \end{lstlisting}
       
   381 
       
   382 \end{frame}
       
   383 
       
   384 \begin{frame}[fragile]
       
   385 
       
   386   \begin{columns}
       
   387         \column{0.25\textwidth}
       
   388         \myemph{\Large 3D data}
       
   389         \column{0.5\textwidth}
       
   390         \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\        
       
   391     \end{columns}
       
   392 \begin{lstlisting}
       
   393 >>> x, y, z = ogrid[-5:5:64j, 
       
   394 ...                -5:5:64j, 
       
   395 ...                -5:5:64j]
       
   396 >>> mlab.contour3d(x*x*0.5 + y*y + 
       
   397                    z*z*2)
       
   398 \end{lstlisting}
       
   399 \end{frame}
       
   400 
       
   401 \begin{frame}[fragile]
       
   402 
       
   403     \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}}
       
   404     \vspace*{0.25in}
       
   405 
       
   406     \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\
       
   407     
       
   408 \begin{lstlisting}
       
   409 >>> mlab.test_quiver3d()
       
   410 \end{lstlisting}
       
   411 
       
   412 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}}
       
   413 \inctime{20}
       
   414 \end{frame}
       
   415 
   193 
   416 
   194 \subsection{Mayavi2}
   417 \subsection{Mayavi2}
   195 
   418 
   196 \begin{frame}
   419 \begin{frame}
   197   \frametitle{Introduction to Mayavi}
   420   \frametitle{Introduction to Mayavi}
   255           \item \alert{Pythonic}
   478           \item \alert{Pythonic}
   256       \end{itemize}
   479       \end{itemize}
   257     
   480     
   258       \inctime{10}
   481       \inctime{10}
   259 
   482 
   260 \end{frame}
       
   261 
       
   262 \subsection{mlab}
       
   263 
       
   264 \begin{frame}
       
   265     {Overview}
       
   266     \Large
       
   267     \begin{itemize}
       
   268         \item Simple
       
   269         \item Convenient
       
   270         \item Full-featured
       
   271     \end{itemize}
       
   272 \end{frame}
       
   273 
       
   274 \begin{frame}[fragile]
       
   275 
       
   276     \frametitle{Getting started}
       
   277     \myemph{\Large Vanilla:}
       
   278     \begin{lstlisting}[language=bash]
       
   279         $ ipython -wthread
       
   280     \end{lstlisting}
       
   281     \myemph{\Large with Pylab:}
       
   282     \begin{lstlisting}[language=bash]
       
   283         $ ipython -pylab -wthread
       
   284     \end{lstlisting}
       
   285 \end{frame}
       
   286 
       
   287 \begin{frame}[fragile]
       
   288     \frametitle{Using mlab}
       
   289 
       
   290     \begin{lstlisting}
       
   291 >>> from enthought.mayavi import mlab
       
   292     \end{lstlisting}
       
   293 
       
   294     \vspace*{0.5in}
       
   295 
       
   296     \myemph{\Large Try these}
       
   297 
       
   298     \vspace*{0.25in}
       
   299 
       
   300     \begin{lstlisting}
       
   301 >>> mlab.test_<TAB>
       
   302 >>> mlab.test_contour3d()
       
   303 >>> mlab.test_contour3d??
       
   304     \end{lstlisting}
       
   305 \end{frame}
       
   306 
       
   307 \begin{frame}
       
   308     {Exploring the view}
       
   309     \begin{columns}
       
   310         \column{0.6\textwidth}
       
   311     \pgfimage[width=3in]{MEDIA/m2/contour3d}
       
   312         \column{0.4\textwidth}
       
   313         \begin{itemize}
       
   314             \item Mouse
       
   315             \item Keyboard
       
   316             \item Toolbar
       
   317             \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon}
       
   318         \end{itemize}
       
   319     \end{columns}
       
   320 \end{frame}
       
   321 
       
   322 \begin{frame}[fragile]
       
   323     \frametitle{\mlab\ plotting functions}
       
   324     \begin{columns}
       
   325         \column{0.25\textwidth}
       
   326         \myemph{\Large 0D data}
       
   327         \column{0.5\textwidth}
       
   328     \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex}
       
   329     \end{columns}
       
   330 
       
   331     \begin{lstlisting}
       
   332 >>> from numpy import *
       
   333 >>> t = linspace(0, 2*pi, 50)
       
   334 >>> u = cos(t)*pi
       
   335 >>> x, y, z = sin(u), cos(u), sin(t)
       
   336     \end{lstlisting}
       
   337     \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}}
       
   338 \end{frame}
       
   339 
       
   340 \begin{frame}
       
   341   \begin{columns}
       
   342         \column{0.25\textwidth}
       
   343         \myemph{\Large 1D data}
       
   344         \column{0.5\textwidth}
       
   345         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   346   \end{columns}
       
   347   \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}}
       
   348 
       
   349     Plots lines between the points
       
   350     
       
   351 \end{frame}
       
   352 
       
   353 \begin{frame}[fragile]
       
   354     \begin{columns}
       
   355         \column{0.25\textwidth}
       
   356         \myemph{\Large 2D data}
       
   357         \column{0.5\textwidth}
       
   358         \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex}
       
   359     \end{columns}            
       
   360     \begin{lstlisting}
       
   361 >>> x = mgrid[-3:3:100j,-3:3:100j]
       
   362 >>> z = sin(x*x + y*y)
       
   363     \end{lstlisting}
       
   364 
       
   365     \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}}
       
   366 
       
   367     \alert{Assumes the points are rectilinear}
       
   368 
       
   369 \end{frame}
       
   370 
       
   371 \begin{frame}[fragile]
       
   372     \myemph{\Large 2D data: \texttt{mlab.mesh}}
       
   373     \vspace*{0.25in}
       
   374 
       
   375     \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}}
       
   376 
       
   377     \alert{Points needn't be regular}
       
   378 
       
   379     \vspace*{0.25in}
       
   380 \begin{lstlisting}
       
   381 >>> phi, theta = numpy.mgrid[0:pi:20j, 
       
   382 ...                         0:2*pi:20j]
       
   383 >>> x = sin(phi)*cos(theta)
       
   384 >>> y = sin(phi)*sin(theta)
       
   385 >>> z = cos(phi)
       
   386 >>> mlab.mesh(x, y, z, 
       
   387 ...           representation=
       
   388 ...           'wireframe')
       
   389 \end{lstlisting}
       
   390 
       
   391 \end{frame}
       
   392 
       
   393 \begin{frame}[fragile]
       
   394 
       
   395   \begin{columns}
       
   396         \column{0.25\textwidth}
       
   397         \myemph{\Large 3D data}
       
   398         \column{0.5\textwidth}
       
   399         \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\        
       
   400     \end{columns}
       
   401 \begin{lstlisting}
       
   402 >>> x, y, z = ogrid[-5:5:64j, 
       
   403 ...                -5:5:64j, 
       
   404 ...                -5:5:64j]
       
   405 >>> mlab.contour3d(x*x*0.5 + y*y + 
       
   406                    z*z*2)
       
   407 \end{lstlisting}
       
   408 \end{frame}
       
   409 
       
   410 \begin{frame}[fragile]
       
   411 
       
   412     \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}}
       
   413     \vspace*{0.25in}
       
   414 
       
   415     \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\
       
   416     
       
   417 \begin{lstlisting}
       
   418 >>> mlab.test_quiver3d()
       
   419 \end{lstlisting}
       
   420 
       
   421 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}}
       
   422 \inctime{20}
       
   423 \end{frame}
   483 \end{frame}
   424 
   484 
   425 \begin{frame}
   485 \begin{frame}
   426     {Getting hands dirty!}
   486     {Getting hands dirty!}
   427 
   487