246 NameError: name 'linspace' is not defined |
246 NameError: name 'linspace' is not defined |
247 \end{lstlisting} |
247 \end{lstlisting} |
248 \end{frame} |
248 \end{frame} |
249 |
249 |
250 \begin{frame}[fragile] |
250 \begin{frame}[fragile] |
251 \frametitle{Remedy} |
|
252 \begin{lstlisting} |
|
253 from scipy import * |
|
254 \end{lstlisting} |
|
255 \alert{Now run python four\_plot.py again!} |
|
256 \pause |
|
257 \begin{lstlisting} |
|
258 Traceback (most recent call last): |
|
259 File "four_plot.py", line 4, in <module> |
|
260 plot(x, x, 'b') |
|
261 NameError: name 'plot' is not defined |
|
262 \end{lstlisting} |
|
263 \end{frame} |
|
264 |
|
265 \begin{frame}[fragile] |
|
266 \frametitle{Remedy \ldots} |
251 \frametitle{Remedy \ldots} |
267 \begin{lstlisting} |
252 \begin{lstlisting} |
268 from pylab import * |
253 from pylab import * |
269 \end{lstlisting} |
254 \end{lstlisting} |
270 \alert{Now run python four\_plot.py again!!} |
255 \alert{Now run python four\_plot.py again!!} |
274 \frametitle{Modules} |
259 \frametitle{Modules} |
275 \begin{itemize} |
260 \begin{itemize} |
276 \item The \kwrd{import} keyword ``loads'' a module |
261 \item The \kwrd{import} keyword ``loads'' a module |
277 \item One can also use: |
262 \item One can also use: |
278 \begin{lstlisting} |
263 \begin{lstlisting} |
279 In []: from scipy import * |
264 In []: from pylab import * |
280 In []: from scipy import linspace |
265 In []: from pylab import linspace |
281 \end{lstlisting} |
266 \end{lstlisting} |
282 \item What is the difference? |
267 \item What is the difference? |
283 \item \alert{Use the former only in interactive mode} |
268 \item \alert{Use the former only in interactive mode} |
284 \end{itemize} |
269 \end{itemize} |
285 \end{frame} |
270 \end{frame} |
295 |
280 |
296 \begin{frame}[fragile] |
281 \begin{frame}[fragile] |
297 \frametitle{\texttt{from} \ldots \texttt{import} - conventional way!} |
282 \frametitle{\texttt{from} \ldots \texttt{import} - conventional way!} |
298 \small |
283 \small |
299 \begin{lstlisting} |
284 \begin{lstlisting} |
300 from scipy import linspace, pi, sin |
285 from pylab import linspace, pi, sin |
301 from pylab import plot, legend, annotate |
286 from pylab import plot, legend, annotate |
302 from pylab import xlim, ylim |
287 from pylab import xlim, ylim |
303 |
288 |
304 x = linspace(-5*pi, 5*pi, 500) |
289 x = linspace(-5*pi, 5*pi, 500) |
305 plot(x, x, 'b') |
290 plot(x, x, 'b') |
315 |
300 |
316 \begin{frame}[fragile] |
301 \begin{frame}[fragile] |
317 \frametitle{\texttt{from} \ldots \texttt{import} - conventional way!} |
302 \frametitle{\texttt{from} \ldots \texttt{import} - conventional way!} |
318 \small |
303 \small |
319 \begin{lstlisting} |
304 \begin{lstlisting} |
320 import scipy |
|
321 import pylab |
305 import pylab |
322 |
306 |
323 x = scipy.linspace(-5*scipy.pi, 5*scipy.pi, 500) |
307 x = pylab.linspace(-5*pylab.pi, 5*pylab.pi, 500) |
324 pylab.plot(x, x, 'b') |
308 pylab.plot(x, x, 'b') |
325 pylab.plot(x, -x, 'b') |
309 pylab.plot(x, -x, 'b') |
326 pylab.plot(x, scipy.sin(x), 'g', linewidth=2) |
310 pylab.plot(x, pylab.sin(x), 'g', linewidth=2) |
327 pylab.plot(x, x*scipy.sin(x), 'r', linewidth=3) |
311 pylab.plot(x, x*pylab.sin(x), 'r', linewidth=3) |
328 pylab.legend(['x', '-x', 'sin(x)', 'xsin(x)']) |
312 pylab.legend(['x', '-x', 'sin(x)', 'xsin(x)']) |
329 pylab.annotate('origin', xy = (0, 0)) |
313 pylab.annotate('origin', xy = (0, 0)) |
330 pylab.xlim(-5*scipy.pi, 5*scipy.pi) |
314 pylab.xlim(-5*pylab.pi, 5*pylab.pi) |
331 pylab.ylim(-5*scipy.pi, 5*scipy.pi) |
315 pylab.ylim(-5*pylab.pi, 5*pylab.pi) |
332 \end{lstlisting} |
316 \end{lstlisting} |
333 \end{frame} |
317 \end{frame} |
334 |
318 |
335 \begin{frame} |
319 \begin{frame} |
336 \frametitle{Modules: Standard library} |
320 \frametitle{Modules: Standard library} |