# HG changeset patch # User Puneeth Chaganti # Date 1289280400 -19800 # Node ID 226b6e789da5b43e2954deea3e4401525463f28e # Parent 43a24f7ab18316ef73d7b4dd894afc5bba51e19c Minor changes to loops, input-output and advanced functions. diff -r 43a24f7ab183 -r 226b6e789da5 advanced-features-functions/script.rst --- a/advanced-features-functions/script.rst Tue Nov 09 10:54:53 2010 +0530 +++ b/advanced-features-functions/script.rst Tue Nov 09 10:56:40 2010 +0530 @@ -169,7 +169,8 @@ welcome() -Let us now learn what keyword arguments are. +Let us now learn what keyword arguments or named arguments are. We +shall refer to them as keyword arguments, henceforth. {{{ show a slide with examples using keyword arguments. }}} @@ -185,14 +186,6 @@ pie(science.values(), labels = science.keys()) -.. #[[Anoop: I think it will better to introduce keyword arguments as - keyword/named arguments, as the keyword term was quite confusing - for me, so can be for someone who already know certain - jargon's/concepts, also it would be good to tell them that these - are different from keywords in programming languages, explicit is - better than implicit, and probably you could also tell them that - from now on we will refer to it as just keyword arguments]] - When you are calling functions in Python, you don't need to remember the order in which to pass the arguments. Instead, you can use the name of the argument to pass it a value. This slide shows a few @@ -249,7 +242,6 @@ .. #[punch: Need to decide, exactly what to put here. Reviewer comments .. welcome.] - {{{ switch to slide showing classes of functions in pylab, scipy }}} .. #[[Anoop: slide missing]] diff -r 43a24f7ab183 -r 226b6e789da5 input_output/script.rst --- a/input_output/script.rst Tue Nov 09 10:54:53 2010 +0530 +++ b/input_output/script.rst Tue Nov 09 10:56:40 2010 +0530 @@ -12,7 +12,7 @@ .. 1. Loops .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Puneeth External Reviewer : Checklist OK? : [2010-10-05] @@ -26,10 +26,10 @@ {{{ Show the slide containing the outline slide }}} Input and Output are used in almost every program we use. -In this tutorial, we shall learn +In this tutorial, we shall learn how to - * Outputting data - * Taking input from the user + * Output data + * Take input from the user type :: @@ -38,7 +38,7 @@ a print a -print a prints the value of a which is obvious. +``print a``, obviously, is printing the value of ``a``. As you can see, even when you type just a, the value of a is shown. But there is a difference. @@ -57,10 +57,12 @@ Moreover when we type just a, the value a is shown only in interactive mode and does not have any effect on the program while running it as a script. +.. #[punch: I think we could show that?] + We shall look at different ways of outputting the data. -print statement also accepts the syntax of C's printf statement. -Various arguments can be passed to print using modifiers. +``print`` statement also accepts the syntax of C's ``printf`` statement. +Various arguments can be passed to ``print`` using modifiers. type :: @@ -69,7 +71,8 @@ z = "zed" print "x is %2.1f y is %d z is %s"%(x,y) -As you can see, the values of x and y are substituted in place of %2.1f and %d +As you can see, the values of x and y are substituted in place of +``%2.1f`` and ``%d`` {{{ Pause here and try out the following exercises }}} @@ -77,12 +80,12 @@ {{{ continue from paused state }}} -We see that the int value of x and float value of y are printed corresponding -to the modifiers used in the print statement. +We see that the ``int`` value of x and ``float`` value of y are +printed corresponding to the modifiers used in the print statement. -We can also see that print statement prints a new line character at the end of -line, everytime it is called. This can be suppressed by using a "," at the end -print statement. +We can also see that ``print`` statement prints a new line character +at the end of the line, everytime it is called. This can be suppressed +by using a "," at the end ``print`` statement. Let us see this by typing out following code on an editor as print_example.py diff -r 43a24f7ab183 -r 226b6e789da5 loops/script.rst --- a/loops/script.rst Tue Nov 09 10:54:53 2010 +0530 +++ b/loops/script.rst Tue Nov 09 10:56:40 2010 +0530 @@ -31,15 +31,14 @@ {{{ Show the outline slide }}} In this tutorial, we shall look at ``while`` and ``for`` loops. We -shall then look at the ``break``, ``continue`` and ``pass`` keywords -and how to use them. +shall then look at how to break out of them, or skip some iterations +in loops. .. #[[Anoop: for loop is a pre-requisite and has been already covered, so i think our emphasize can be on while loops]] -.. #[[Anoop: Instead of saying we will learn keywords pass, break and - continue, I think it is better to tell them that we will learn more - about loops]] +.. #[[punch: I think, we should have both of them. It gives a better +.. context and comparison.] {{{ switch to the ipython terminal }}} @@ -144,8 +143,8 @@ .. #[[Anoop: should add slides for break, continue, pass]] Say, we wish to print the squares of all the odd numbers below 10, -which are not multiples of 3, we would modify the for loop as follows. -:: +which are not multiples of 3, we would modify the ``for`` loop as +follows. :: for n in range(1, 10, 2): if n%3 == 0: @@ -157,12 +156,9 @@ {{{ switch to next slide }}} -%%3%%Using the ``continue`` keyword modify the ``for`` loop to print -the squares of even numbers below 10, to print the squares of only -multiples of 4. (Do not modify the range function call.) - -.. #[[Anoop: can you be more explicit/specific on do no modify say we - can ask them to use range(2, 10, 2) and solve the problem]] +%%3%%Using the ``continue`` keyword modify the ``for`` loop, with the +``range(2, 10, 2)``, to print the squares of even numbers below 10, to +print the squares of only multiples of 4. Please, pause the video here. Do the exercise and then continue. diff -r 43a24f7ab183 -r 226b6e789da5 plotui/buttons.png Binary file plotui/buttons.png has changed diff -r 43a24f7ab183 -r 226b6e789da5 plotui/move.png Binary file plotui/move.png has changed diff -r 43a24f7ab183 -r 226b6e789da5 plotui/questions.rst --- a/plotui/questions.rst Tue Nov 09 10:54:53 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -Objective Questions -------------------- - -.. A mininum of 8 questions here (along with answers) - -1. Create 100 equally spaced points between -pi/2 and pi/2? - - Answer: linspace(-pi/2,pi/2,100) - -2. How do you clear a figure in ipython? - - Answer: clf() - -3. How do find the length of a sequence? - - Answer: len(sequence_name) - -4. Create a plot of x and e^x where x is 100 equally spaced points between 0,pi. Hint: e^x -> exp(x) for ipython - - Answer: x=linspace(0,pi,100) - plot(x,exp(x)) - -5. List four formats in which you can save a plot in ipython? - - Answer: png,eps,pdf,ps - -6. List the kind of buttons available in plotui to study the plot better ? - - Zoom button to Zoom In to a region. - Pan button to move it around. - -7. What are the left and right arrow buttons for? - - Answer: These buttons take you to the states that the plot has been. Much like a browser left and right arrow button. - - - -8. What is the home button for in the Plot UI? - - Initial State of the plot. - - - - -Larger Questions ----------------- - -.. A minimum of 2 questions here (along with answers) - -1. Use '?' and explain the similarities and difference between linpace and logspace? -2. Describe one by one all the buttons in UI of plot and their meaning? diff -r 43a24f7ab183 -r 226b6e789da5 plotui/quickref.tex --- a/plotui/quickref.tex Tue Nov 09 10:54:53 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} - -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} - -Saving Plot\\ -{\includegraphics[width=60mm]{save.png}} - -Zooming into a part of the plot\\ -{\includegraphics[width=60mm]{zoom.png}} - -Move the plot\\ -{\includegraphics[width=60mm]{move.png}} diff -r 43a24f7ab183 -r 226b6e789da5 plotui/save.png Binary file plotui/save.png has changed diff -r 43a24f7ab183 -r 226b6e789da5 plotui/script.rst --- a/plotui/script.rst Tue Nov 09 10:54:53 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +0,0 @@ -.. Objectives -.. ---------- - -.. By the end of this tutorial you will -- - -.. 1. Create simple plots of mathematical functions -.. #. Use the Figure window to study plots better - - - -.. Prerequisites -.. ------------- - -.. Installation of required tools -.. Ipython - -.. Author : Amit Sethi - Internal Reviewer : - External Reviewer : - Checklist OK? : [2010-10-05] - -Script -------- - - -Hello and welcome to the tutorial on creating simple plots using -Python.This tutorial is presented by the Fossee group. -{{{ Show the Title Slide }}} - -I hope you have IPython running on your computer. - -In this tutorial we will look at plot command and also how to study -the plot using the UI. - -{{{ Show Outline Slide }}} - -Lets start ipython on your shell, type :: - - $ipython -pylab - - -Pylab is a python library which provides plotting functionality.It -also provides many other important mathematical and scientific -functions. After running IPython -pylab in your shell if at the top of -the result of this command, you see something like :: - - - `ERROR: matplotlib could NOT be imported! Starting normal - IPython.` - - -{{{ Slide with Error written on it }}} - - - - -Then you have to install matplotlib and run this command again. - -Now type in your ipython shell :: - - In[]: linpace? - - - -as the documentation says, it returns `num` evenly spaced samples, -calculated over the interval start and stop. To illustrate this, lets -do it form 1 to 100 and try 100 points. :: - - In[]: linspace(1,100,100) - -As you can see a sequence of numbers from 1 to 100 appears. - -Now lets try 200 points between 0 and 1 you do this by typing :: - - - In[]: linspace(0,1,200) - -0 for start , 1 for stop and 200 for no of points. In linspace -the start and stop points can be integers, decimals , or -constants. Let's try and get 100 points between -pi to pi. Type :: - - In[]: p = linspace(-pi,pi,100) - - -'pi' here is constant defined by pylab. Save this to the variable, p -. - -If you now :: - - In[]: len(p) - -You will get the no. of points. len function gives the no of elements -of a sequence. - - -Let's try and plot a cosine curve between -pi and pi using these -points. Simply type :: - - - In[]: plot(p,cos(points)) - -Here cos(points) gets the cosine value at every corresponding point to -p. - - -We can also save cos(points) to variable cosine and plot it using -plot.:: - - In[]: cosine=cos(points) - - In[]: plot(p,cosine) - - - -Now do :: - - In[]: clf() - -this will clear the plot. - -This is done because any other plot we try to make shall come on the -same drawing area. As we do not wish to clutter the area with -overlaid plots , we just clear it with clf(). Now lets try a sine -plot. :: - - - In []: plot(p,sin(p)) - - - - -The Window on which the plot appears can be used to study it better. - -{{{ Show the slide with all the buttons on it }}} - -First of all moving the mouse around gives us the point where mouse -points at. - -Also we have some buttons the right most among them is -for saving the file. - -Just click on it specifying the name of the file. We will save the plot -by the name sin_curve in pdf format. - - - -{{{ Action corelating with the words }}} - -As you can see I can specify format of file from the dropdown. - -Formats like png ,eps ,pdf, ps are available. - -Left to the save button is the slider button to specify the margins. - -{{{ Action corelating with the words }}} - -Left to this is zoom button to zoom into the plot. Just specify the -region to zoom into. -The button left to it can be used to move the axes of the plot. - -{{{ Action corelating with the words }}} - -The next two buttons with a left and right arrow icons change the state of the -plot and take it to the previous state it was in. It more or less acts like a -back and forward button in the browser. - -{{{ Action corelating with the words }}} - -The last one is 'home' referring to the initial plot. - -{{{ Action corelating with the words}}} - - - -{{{ Summary Slide }}} - - -In this tutorial we have looked at - -1. Starting Ipython with pylab - -2. Using linspace function to create `num` equaly spaced points in a region. - -3. Finding length of sequnces using len. - -4. Plotting mathematical functions using plot. - -4. Clearing drawing area using clf - -5. Using the UI of plot for studying it better . Using functionalities like save , zoom and moving the plots on x and y axis - - - - - -{{{ Show the "sponsored by FOSSEE" slide }}} - - - -This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India - - - - Hope you have enjoyed and found it useful. - - Thankyou - - - -Author : Amit Sethi -Internal Reviewer : -Internal Reviewer 2 : diff -r 43a24f7ab183 -r 226b6e789da5 plotui/slides.tex --- a/plotui/slides.tex Tue Nov 09 10:54:53 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -% Created 2010-10-20 Wed 21:57 -\documentclass[presentation]{beamer} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} -\usepackage[latin1]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{graphicx} -\usepackage{longtable} -\usepackage{float} -\usepackage{wrapfig} -\usepackage{soul} -\usepackage{amssymb} -\usepackage{hyperref} - - -\title{Plotting Data } -\author{FOSSEE} -\date{2010-09-14 Tue} - -\begin{document} - -\maketitle - -\begin{frame} -\frametitle{Tutorial Plan} -\label{sec-1} -\begin{itemize} - -\item Creating a simple plot\\ -\label{sec-1.1}% -\item Use the buttons on window to study the plot\\ -\label{sec-1.2}% -\end{itemize} % ends low level -\end{frame} -\begin{frame} -\frametitle{Error if Ipython not installed} -\label{sec-2} -\begin{itemize} - -\item `ERROR: matplotlib could NOT be imported! Starting normal IPython.`\\ -\label{sec-2.1}% -\end{itemize} % ends low level -\end{frame} -\begin{frame} -\frametitle{Plot UI} -\label{sec-3} -\begin{frame} - \begin{center} - \includegraphics[height=1.0in,width=4.2in]{buttons.png} - \end{center} -\end{frame} - -\frametitle{Summary} -\label{sec-4} -\begin{itemize} - -\item Start Ipython with pylab\\ -\label{sec-4.1}% -\item Using linspace\\ -\label{sec-4.2}% -\item Finding length of sequnces using len.\\ -\label{sec-4.3}% -\item Plotting mathematical functions using plot.\\ -\label{sec-4.4}% -\item Clearing drawing area using clf\\ -\label{sec-4.5}% -\item Using the UI of plot\\ -\label{sec-4.6}% -\end{itemize} % ends low level -\end{frame} - -\end{document} diff -r 43a24f7ab183 -r 226b6e789da5 plotui/zoom.png Binary file plotui/zoom.png has changed