summaryrefslogtreecommitdiff
path: root/scipy/basic/mlab.tex
blob: bb2e4eb16dbdfa7e17d800922d1d12bb5ab3ec28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Tutorial slides on Python.
%
% Author: FOSSEE
% Copyright (c) 2009-2016, FOSSEE, IIT Bombay
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[14pt,compress]{beamer}
%\documentclass[draft]{beamer}
%\documentclass[compress,handout]{beamer}
%\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]

% Modified from: generic-ornate-15min-45min.de.tex
\mode<presentation>
{
  \usetheme{Warsaw}
  \useoutertheme{infolines}
  \setbeamercovered{transparent}
}

\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
%\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{pgf}

% Taken from Fernando's slides.
\usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler}
\usepackage[scaled=.95]{helvet}
\usepackage{amsmath}

\definecolor{darkgreen}{rgb}{0,0.5,0}

\usepackage{listings}
\lstset{language=Python,
    basicstyle=\ttfamily\bfseries,
    commentstyle=\color{red}\itshape,
  stringstyle=\color{darkgreen},
  showstringspaces=false,
  keywordstyle=\color{blue}\bfseries}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Macros
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
\newcommand{\emphbar}[1]
{\begin{beamercolorbox}[rounded=true]{emphbar}
      {#1}
 \end{beamercolorbox}
}

\newcommand{\myemph}[1]{\structure{\emph{#1}}}
\newcommand{\PythonCode}[1]{\lstinline{#1}}

\newcounter{time}
\setcounter{time}{0}
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}

\newcommand{\typ}[1]{\lstinline{#1}}

\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }

%%% This is from Fernando's setup.
% \usepackage{color}
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
% % Use and configure listings package for nicely formatted code
% \usepackage{listings}
% \lstset{
%    language=Python,
%    basicstyle=\small\ttfamily,
%    commentstyle=\ttfamily\color{blue},
%    stringstyle=\ttfamily\color{orange},
%    showstringspaces=false,
%    breaklines=true,
%    postbreak = \space\dots
% }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
\title[Basic SciPy and Mayavi]{Introductory Scientific Computing with
Python}
\subtitle{Simple 3D plots with Mayavi's mlab}

\author[Prabhu] {FOSSEE}

\institute[FOSSEE -- IITB] {Department of Aerospace Engineering\\IIT Bombay}
\date[] {SciPy India, 2016\\
Mumbai
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
%\logo{\pgfuseimage{iitmlogo}}


%% Delete this, if you do not want the table of contents to pop up at
%% the beginning of each subsection:
\AtBeginSubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\AtBeginSection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:
%\beamerdefaultoverlayspecification{<+->}

%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DOCUMENT STARTS
\begin{document}

\begin{frame}
  \maketitle
\end{frame}

\section{Introduction to Mayavi}

\begin{frame}
  \frametitle{Mayavi}
  \begin{itemize}
  \item 3D visualization library
  \item Application
  \item Support for different data formats
  \item Embeddable, extensible
  \item Cross-platform
  \item Fully scriptable
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Installation}
  \begin{itemize}
  \item Suggest using a Python distribution
  \item Canopy's package manager
  \item \typ{conda}
  \item \typ{edm}
  \end{itemize}
\end{frame}

\section{Getting started with mlab}

\begin{frame}
  {Overview}
  \begin{itemize}
  \item Simple
  \item Convenient
  \item Full-featured
  \end{itemize}
\end{frame}

\begin{frame}[plain,fragile]
  \frametitle{Getting started}

 \myemph{With \typ{jupyter}:}
\begin{lstlisting}[language=bash]
    $ jupyter console
    In [1]: %gui qt
\end{lstlisting} %$
 \vspace*{0.15in}

  \myemph{Vanilla:}
\begin{lstlisting}[language=bash]
    $ ipython --gui=qt
\end{lstlisting} %$
 \vspace*{0.15in}

\myemph{Or:}
\begin{lstlisting}[language=bash]
    $ ipython
    In [1]: %gui qt
\end{lstlisting} %$

\end{frame}

\begin{frame}[fragile,plain]
  \frametitle{Using notebooks}

  Make sure you have the following code first:

\begin{lstlisting}
    In [1]: from mayavi import mlab
    In [2]: mlab.init_notebook()
\end{lstlisting}

  \begin{itemize}
    \item Can also use \typ{\%gui qt}
    \item Plots will pop-up
  \end{itemize}

\end{frame}

\section{Basic Mayavi: \typ{mlab}}

\begin{frame}[fragile]
\frametitle{Basic 3D visualization}
\begin{itemize}
    \item Simple one liners for 3D visualization
    \item Must import mlab.
\end{itemize}
\begin{lstlisting}
In []: from mayavi import mlab
\end{lstlisting}
Ready to go!
\end{frame}

\begin{frame}[fragile]
    \frametitle{Simple examples}

    \myemph{\Large Try these}

    \begin{lstlisting}
In []: mlab.test_<TAB>

In []: mlab.test_points3d()
In []: mlab.clf()
In []: mlab.test_plot3d()
In []: mlab.clf()
In []: mlab.test_surf()
In []: mlab.test_surf??
    \end{lstlisting}
Explore the UI.
\end{frame}


\begin{frame}[fragile]
    \frametitle{\typ{mlab} plotting functions}
    \begin{columns}
        \column{0.25\textwidth}
        \myemph{\Large 0D data}
        \column{0.5\textwidth}
    \pgfimage[width=2in]{mlab_data/points3d_ex}
    \end{columns}

    \begin{lstlisting}
In []: t = linspace(0, 2*pi, 50)
In []: u = cos(t) * pi
In []: x, y, z = sin(u), cos(u), sin(t)
    \end{lstlisting}
    \emphbar{\PythonCode{In []: mlab.points3d(x, y, z)}}
\end{frame}

\begin{frame}[plain, fragile]
    \frametitle{Changing how things look}

    \begin{block}{Clearing the view}
    \PythonCode{>>> mlab.clf()}
    \end{block}

    \pause

    \begin{block}{IPython is your friend!}
    \PythonCode{>>> mlab.points3d?}

    \begin{itemize}

        \item Extra argument: Scalars

        \item Keyword arguments

        \item UI
    \end{itemize}
    \end{block}
\pause
    \begin{lstlisting}
In []: mlab.points3d(x, y, z, t,
                     scale_mode='none')
    \end{lstlisting}

\end{frame}



\begin{frame}[fragile]
  \begin{columns}
        \column{0.25\textwidth}
        \myemph{\Large 1D data}
        \column{0.5\textwidth}
        \pgfimage[width=2.5in]{mlab_data/plot3d_ex}
  \end{columns}
  \emphbar{\PythonCode{In []: mlab.plot3d(x, y, z, t)}}

    Plots lines between the points

\end{frame}

\begin{frame}[fragile]
    \begin{columns}
        \column{0.25\textwidth}
        \myemph{\Large 2D data}
        \column{0.5\textwidth}
        \pgfimage[width=2in]{mlab_data/surf_ex}
    \end{columns}
    \begin{lstlisting}
In []: x, y = mgrid[-3:3:100j,-3:3:100j]
In []: z = sin(x*x + y*y)
    \end{lstlisting}

    \emphbar{\PythonCode{In []: mlab.surf(x, y, z)}}

    \alert{Assumes the points are rectilinear}

\end{frame}


\begin{frame}[plain, fragile]

        \myemph{\Large 3D data}
    \vspace*{0.25in}

    \pgfimage[width=1.5in]{mlab_data/contour3d}\\

\begin{lstlisting}
In []: x, y, z = ogrid[-5:5:64j,
  ...:                 -5:5:64j,
  ...:                 -5:5:64j]
In []: mlab.contour3d(x*x*0.5 + y*y +
                   z*z*2)
\end{lstlisting}
\end{frame}

\begin{frame}[plain]
    {Other utility functions}
    \begin{itemize}
        \item \PythonCode{gcf}: get current figure
            \pause
        \item \PythonCode{savefig}, \PythonCode{figure}
           \pause
        \item \PythonCode{axes}, \PythonCode{outline}
            \pause
        \item \PythonCode{title}, \PythonCode{xlabel, ylabel, zlabel}
            \pause
        \item \PythonCode{colorbar}, \PythonCode{scalarbar},
            \PythonCode{vectorbar}
            \pause
        \item \PythonCode{show}: Standalone mlab scripts
            \pause
        \item Others, see UG
    \end{itemize}
\end{frame}

\begin{frame}
    {Exploring the documentation}
    \begin{center}
    \pgfimage[width=4in]{mlab_data/m2_ug_doc}
    \end{center}
    \inctime{20}
\end{frame}



\begin{frame}
    \frametitle{Further reading}
    \begin{itemize}
        \item \url{github.enthought.com/mayavi/mayavi}
    \end{itemize}
\end{frame}

\end{document}