From 5b2a47fe5b602c5763810441ac8907487dc429b7 Mon Sep 17 00:00:00 2001 From: Medini Kadam Date: Wed, 27 Apr 2011 16:26:41 +0530 Subject: Revised entire script of 'Using plot interactively'. Rephrased few sentences to make them simple and less dramatic. Changed few minor sequences to maintain the flow of instructions. Some instructions were found to be incomplete hence tried to complete them. --- using_plot_interactively/script.rst | 71 ++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/using_plot_interactively/script.rst b/using_plot_interactively/script.rst index 43393cb..5de2c30 100644 --- a/using_plot_interactively/script.rst +++ b/using_plot_interactively/script.rst @@ -4,7 +4,7 @@ .. By the end of this tutorial you will -- .. 1. Create simple plots of mathematical functions -.. #. Use the Figure window to study plots better +.. 2. Use features of graphical window to manipulate plots @@ -30,7 +30,8 @@ team along with the logo of MHRD }}} Hello Friends and welcome to the tutorial on creating simple plots using iPython. -I hope you have IPython running on your computer. +I hope you have IPython installed on your computer if not, then refer to the spoken tutorial +on instaling ipython. .. L2 @@ -39,16 +40,16 @@ I hope you have IPython running on your computer. At the end of this tutorial, you will be able to, 1. Create simple plots of mathematical functions. - #. Use the Figure window to study plots better. + 2. Use features of graphical window to manipulate plots .. R2 -In this tutorial we will learn how to plot using the plot command and how to use the user interface of plot figure. + .. R3 -Lets start ipython.Open the terminal and type +To start ipython, Open the terminal and type ipython -pylab and hit enter. .. L3 @@ -61,21 +62,31 @@ ipython -pylab and hit enter. Pylab is a python library which provides plotting functionality.It provides many other important mathematical and scientific -functions. After running IPython -pylab in the shell you will see some -information about ipython and pylab followed by the In[1] prompt.But if you get an error like :: +functions. +After running IPython -pylab in your shell, +the screen will look like this. + +.. Pause the video for 2 sec then continue. + +But instead if you get the following error like:: + +- show the error slide `ERROR: matplotlib could NOT be imported! Starting normal IPython.` Then you will have to install the matplotlib and run this command again. +.. Add some instruction to help user to install matplotlib. + .. L4 {{{ Slide with Error written on it }}} .. R5 -Now type 'linspace' followed by a '?' mark in your ipython shell +To get array of numbers we use linspace command. +Type 'linspace' followed by a '?' mark to get detailed documentation/help of it .. L5 @@ -85,10 +96,9 @@ Now type 'linspace' followed by a '?' mark in your ipython shell .. R6 -as the documentation says, it returns `num` evenly spaced samples, +As the documentation says, it returns `num` evenly spaced samples, calculated over the interval start and stop. To illustrate this, lets try to generate 100 points.Type ``linspace(1,100,100)`` and hit enter. -As you can see a sequence of numbers from 1 to 100 appears. .. L6 @@ -96,9 +106,11 @@ As you can see a sequence of numbers from 1 to 100 appears. linspace(1,100,100) +As you can see a sequence of numbers from 1 to 100 appears. + .. R7 -Now lets try to generate 200 points between 0 and 1,we do that by typing linspace(0,1,200). +To generate 200 points between 0 and 1, type linspace(0,1,200). .. L7 @@ -108,10 +120,10 @@ Now lets try to generate 200 points between 0 and 1,we do that by typing linspa .. R8 -Here,0 is the start , 1 the stop and 200 the number of points.In linspace +Here,0 is the start , 1 is the stop and 200 is the number 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.Here 'pi' is a constant -defined by pylab. Save this to the variable,say p. +To get 100 points between -pi to pi where 'pi' is a constant +defined by pylab and save the result to the variable,say p. Type p=linspace(-pi,pi,100). .. L8 @@ -121,9 +133,7 @@ defined by pylab. Save this to the variable,say p. .. R9 -If we now type ``len(p)`` -we will get the no. of points. len function gives the no of elements -of a sequence. +To get the number of elements or points of a sequence say p type ''len(p)'' .. L9 @@ -134,7 +144,7 @@ of a sequence. .. R10 -Let's try and plot a cosine curve between -pi and pi.For this we use the plot command. +To plot a cosine curve between -pi and pi, we use the plot command. Here cos(p) gets the cosine value at every point corresponding to point p. @@ -158,7 +168,7 @@ plot function. .. R12 -Now to clear the plot ,we use the ``clf()`` function +To clear the plot, use the ``clf()`` function .. L12 @@ -168,8 +178,9 @@ Now to clear the plot ,we use the ``clf()`` function .. R13 -This is done because if we wish to make another plot,it will overlap the previous plot. -As we do not wish to clutter the area with overlaid plots , we just clear it with clf(). +If the plot is not cleared, then any new plot will overlap the previous plot. Hence to avoid +cluttering the area with overlaid plots use clf() function. + Now lets try a sine plot. .. L13 @@ -180,7 +191,7 @@ Now lets try a sine plot. .. R14 -We can study the plot better on the plot window by using the various options available on it.Let us have a look at these options. +We can manipulate the plot in the graphical window. .. L14 @@ -188,7 +199,8 @@ We can study the plot better on the plot window by using the various options ava .. R15 -As we can observe, moving the mouse pointer along the plot gives us the location of each point on the plot +The location of the mouse pointer on the window is displayed in bottom right corner of the window. +By moving the mouse pointer the location of each point is seen. .. L15 @@ -198,9 +210,9 @@ As we can observe, moving the mouse pointer along the plot gives us the location To the bottom left of the window,there are a few buttons.The right most among them is for saving the file. -Just click on it and type the file name. We will save the plot +Just click on it and type the file name in the box provided. We will save the plot by the name `sin_curve` in pdf format.As you can see we can specify the format -of file from the dropdown.Formats like png ,eps ,pdf, ps are available. +of file from the dropdown. Formats like png ,eps ,pdf, ps are also available. .. L16 @@ -255,7 +267,8 @@ The last one is 'home' referring to the initial plot. .. R22 -Following is an exercise that you must do.Please, pause the video and do the exercise. +Pause the video and do this exercise. Resume the video once done. + Plot (sin(x)*sin(x))/x. @@ -274,9 +287,9 @@ Let's revise quickly what we have learnt today 1. To Start Ipython with pylab. #. To Use the linspace function to create `num` equally spaced points in a region. #. To Find the length of sequnces using len function. - #. To Plot mathematical functions using plot. - #. To Clear drawing area using clf. - #. To Use the UI of plot for studying it better and using functionalities like save,zoom and moving the plots on x and y axis. + #. To Plot mathematical functions using plot function. + #. To Clear drawing area using clf function. + #. Manipulate the plot in the window itself by using functionalities like save, zoom, move, home, arrow buttons. .. L24 -- cgit From 27ab28ee115a0bc680ce31b2de198c6f8bb5da87 Mon Sep 17 00:00:00 2001 From: Jovina Date: Thu, 28 Apr 2011 21:56:12 -0700 Subject: Corrected the solution for the 2nd self assessment question. --- getting_started_with_ipython/slides.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started_with_ipython/slides.tex b/getting_started_with_ipython/slides.tex index d48224d..f9be7b9 100644 --- a/getting_started_with_ipython/slides.tex +++ b/getting_started_with_ipython/slides.tex @@ -182,7 +182,7 @@ In this tutorial, we have learnt to -- \begin{itemize} \item False \vspace*{10pt} -\item Ctrl + C +\item Ctrl + D \vspace*{10pt} \item ? \end{itemize} -- cgit From ba36be48b6904f5ddd4f58e9b085504bf60b911d Mon Sep 17 00:00:00 2001 From: Medini Kadam Date: Fri, 29 Apr 2011 14:26:18 +0530 Subject: Revised the entire script of 'Embellishing plots'. --- embellishing_a_plot/script.rst | 148 +++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 79 deletions(-) diff --git a/embellishing_a_plot/script.rst b/embellishing_a_plot/script.rst index b5cfe71..b5a1cfb 100644 --- a/embellishing_a_plot/script.rst +++ b/embellishing_a_plot/script.rst @@ -31,7 +31,7 @@ team along with the logo of MHRD }}} .. R1 -Hello friends and welcome to the tutorial on Embellishing Plots. +Welcome to the tutorial on Embellishing Plots. .. L2 @@ -50,7 +50,7 @@ At the end of this tutorial, you will be able to, .. R3 -Let us start ipython with pylab loaded,open the terminal and type +Let us start ipython with pylab loaded, open the terminal and type :: ipython -pylab @@ -76,9 +76,8 @@ As we can see, the default colour and the default thickness of the line is as decided by pylab. Wouldn't it be nice if we could control these parameters in the plot? This is possible by passing additional arguments to the plot command. -The additional argument that we shall be passing in here now is the -colour argument. We shall first clear the figure and plot the same now in -red colour. +We shall first clear the figure and plot the same by passing the additional color +argument. Pass the argument 'r' for red color. .. L5 @@ -89,7 +88,7 @@ red colour. .. R6 -As we can see we have the same plot but now in red colour. +The same plot is seen in red color. .. L6 @@ -97,8 +96,7 @@ As we can see we have the same plot but now in red colour. .. R7 -To alter the thickness of the line, we use the ``linewidth`` argument -in the plot command. +The thickness of the line can be altered by 'linewidth' argument. .. L7 @@ -108,8 +106,7 @@ in the plot command. .. R8 -This produces a plot with a thicker line, to be more precise plot with line -thickness 2. +A plot with line thickness 2 is produced. .. L8 @@ -117,7 +114,7 @@ thickness 2. .. R9 -Let's try out the following exercise +Pause the video and do this exercise. Resume the video, after the exercise is solved. Plot sin(x) in blue colour and with linewidth as 3. @@ -139,10 +136,8 @@ A combination of colour and linewidth would do the job for us. .. R11 -Occasionally we would also want to alter the style of line. Sometimes -all we want is just a bunch of points not joined. This is possible by -passing the linestyle argument along with or instead of the colour -argument. +To get the style of line as bunch of points not joined, pass the linestyle +argument with or without color argument. .. L11 @@ -153,7 +148,7 @@ argument. .. R12 -Hence we get a plot with only points. +We get a plot with only points. .. L12 @@ -161,7 +156,7 @@ Hence we get a plot with only points. .. R13 -We can produce the same plot but now in blue colour. +To get the same plot in blue colour. .. L13 @@ -170,7 +165,9 @@ We can produce the same plot but now in blue colour. plot(x, sin(x), 'b.') .. R14 -Other available options can be seen in the documentation of plot. + +Other available options for passing arguments can be seen in the +documentation of plot. .. L14 @@ -189,14 +186,15 @@ Other available options can be seen in the documentation of plot. .. R15 -Try out the following exercises +Pause the video and do this exercise. Resume the video, after the exercise is solved. -Plot the sine curve with green filled circles. +1. Plot the sine curve with green filled circles. +2. Plot the curve of x vs tan(x) in red dashed line and linewidth 3. .. R16 -All we have to do is use a combination of linestyle and colour to acheive this. +For question 1, use a combination of linestyle and colour. .. L16 @@ -208,15 +206,7 @@ All we have to do is use a combination of linestyle and colour to acheive this. .. L17 -{{{Show slide containing question 3}}} - -.. R17 - -Let us try out one more exercise - -Plot the curve of x vs tan(x) in red dashed line and linewidth 3. - -.. L18 +For question 2, use a combination of linewidth argument and linestyle. {{{ Switch to terminal and type the following commands }}} :: @@ -227,7 +217,7 @@ Plot the curve of x vs tan(x) in red dashed line and linewidth 3. .. R19 Now that we know how to produce a bare minimum plot with colour, style -and thickness of our interest, we shall look at decorating the plot. +and thickness of our interest, we shall look at further decorating the plot. .. R20 @@ -243,30 +233,28 @@ Let us start with a plot for the function -x^2 + 4x - 5. .. R21 -We now have the plot in a colour and linewidth of our interest. As you -can see, the figure does not have any description describing the plot. +As you can see, the figure does not have any description describing the plot. -We will now add a title to the plot by using the ``title`` command. +To add a title to the plot to describe what the plot is, use the ``title`` command. .. L21 :: - title("Parabolic function -x^2+4x-5") + title("Parabolic function -x^2+4x-5") + +The ``title`` command as you can see, takes a string as an argument {{{ Show the plot window and point to the title }}} .. R22 -The figure now has a title which describes what the plot is. The -``title`` command as you can see, takes a string as an argument and sets -the title accordingly. +The figure now has a title. But it is not formatted and does not look clean. -The formatting in the title is messed and it does not look clean. You can imagine -what would be the situation if there were fractions and more complex functions -like log and exp. Wouldn't it be good if there was LaTeX like formatting? +It would look shabby if there were fractions and more complex functions +like log and exp. Wouldn't it be good if the title is seen in LaTeX like formatting? -That is also possible by adding a ``$`` sign before and after the part of the +This is possible by adding a ``$`` sign before and after the part of the string that should be in LaTeX style. .. L22 @@ -277,7 +265,7 @@ string that should be in LaTeX style. .. R23 -As we can see we get the polynomial formatted properly. +As we can see, the polynomial is now formatted. .. L23 @@ -287,6 +275,8 @@ As we can see we get the polynomial formatted properly. {{{Show slide containing question 4}}} +Pause the video and do this exercise. Resume the video, after the exercise is solved. + .. R24 {{{ Let us try out the following exercise }}} @@ -306,37 +296,35 @@ The solution is to enclose the whole string in between $. .. R26 -Hence it gives a title that looks neatly formatted. - Although we have title, the plot is not complete without labelling x -and y axes. Hence we shall label x-axis to "x" and y-axis to "f(x)". +and y axes. we shall label x-axis to "x" and y-axis to "f(x)". .. L26 :: xlabel("x") + ylabel("f(x)") .. L27 -{{{ Switch to plot window and show the xlabel }}} + .. R27 -As you can see, ``xlabel`` command takes a string as an argument, -similar to the ``title`` command and sets it as the label to x-axis. +As you can see, ``xlabel`` and 'ylabel' command takes a string as an argument. +xlabel sets the label to x-axis as 'x' and ylabel sets the name to the y-axis as 'f(x)'. .. R28 -Similarly, ``ylabel("f(x)")`` sets the name of the y-axis as "f(x)" + .. L28 :: - ylabel("f(x)") -{{{ Show the plot window and point to ylabel and switch back to the terminal }}} +{{{ Show the plot window and point to xlabel and ylabel and switch back to the terminal }}} .. L29 @@ -344,16 +332,18 @@ Similarly, ``ylabel("f(x)")`` sets the name of the y-axis as "f(x)" .. R29 -Now lets try out this exercise. +Pause the video and do this exercise. Resume the video, after the exercise is solved. Set the x and y labels as "x" and "f(x)" in LaTeX style. +{{{ Pause for some time and then Show slide with answer 5 }}} + Since we need LaTeX style formatting, all we have to do is enclose the string in between two $. .. L30 -{{{ Pause for some time and then Show slide with answer 5 }}} + .. R30 @@ -362,17 +352,15 @@ in between two $. xlabel("$x$") ylabel("$f(x)$") -does the job for us. - .. L31 {{{ Show the plot window with clean labels }}} .. R31 -The plot is now almost complete. Except that we have still not seen how to -name the points. For example the point (2, -1) is the local maxima. We would -like to name the point accordingly. We can do this by using the function ``annotate``. +The plot is now almost complete. Except that the points are not named. +For example the point (2, -1) is the local maxima. We would +like to name the point accordingly. To do this use the function ``annotate``. .. L31 @@ -397,7 +385,7 @@ The first is x co-ordinate and second is y co-ordinate. .. R33 -Let's try out this exercise. +Pause the video and do this exercise. Resume the video, after the exercise is solved. Make an annotation called "root" at the point (-4, 0). What happens to the first annotation ? @@ -418,11 +406,12 @@ What happens to the first annotation ? As we can see, every annotate command makes a new annotation on the figure. -Now we have everything we need to decorate a plot. but the plot would be -incomplete if we can not set the limits of axes. This is possible using the -button on the plot window. +Now we have everything we need to decorate a plot, but the plot would be +incomplete if we can not set the limits of axes. This can be done using the +button provided on the plot window. -we shall look at how to get and set them from the terminal.We use "xlim()" and "ylim()" functions. +Else limits also can be get and set from the terminal. +Use "xlim()" and "ylim()" functions to get the limits. .. L35 @@ -433,10 +422,10 @@ we shall look at how to get and set them from the terminal.We use "xlim()" and " .. R35 -We see that ``xlim`` function returns the current x axis limits and ``ylim`` +``xlim`` function returns the current x axis limits and ``ylim`` function returns the current y-axis limits. -Let us look at how to set the limits. +Set the limits of x-axis from -4 to 5 by giving command xlim(-4,5). .. L36 @@ -446,11 +435,9 @@ Let us look at how to set the limits. .. R36 -We see the limits of x-axis are now set to -4 and 5. - .. R37 -Similarly we set the limits of y-axis appropriately. +Similarly set the limits of y-axis appropriately. .. L37 @@ -463,6 +450,8 @@ Similarly we set the limits of y-axis appropriately. {{{ Pause here and try out the following exercises }}} +Pause the video and do this exercise. Resume the video, after the exercise is solved. + {{{Show slide containing question 7 and read it out }}} Set the limits of axes such that the area of interest is the rectangle (-1, -15) and (3, 0) @@ -471,8 +460,8 @@ Set the limits of axes such that the area of interest is the rectangle (-1, -15) .. R38 -As we can see, the lower upper limits of x-axis in the question are -1 and 3. -The limits of y-axis are -15 and 0. +As we can see, the lower and upper limits of x-axis in the question are -1 and 3 respectively. +The lower and upper limits of y-axis are -15 and 0 respectively. .. L39 @@ -485,7 +474,7 @@ The limits of y-axis are -15 and 0. .. R39 -Hence xlim with limits -1 & 3 and ylim with limits -15 & 0 gives us the required rectangle. +This gives us the required rectangle. .. L40 @@ -493,14 +482,15 @@ Hence xlim with limits -1 & 3 and ylim with limits -15 & 0 gives us the required .. R40 -let's revise quickly what we have learnt today. +Lets Summarize. In this spoken tutorial we have learnt, - 1. to Modify the attributes of plot by passing additional arguments. - #. to add title to a plot. - #. to incorporate LaTeX style formatting. - #. to label x and y axes. - #. to add annotations to a plot. - #. to set the limits of axes. + 1. to Modify the attributes of plot like color, line width, line style by passing additional arguments. + #. to add title to a plot using 'title' command. + #. to incorporate LaTeX style formatting by adding a ``$`` sign before and after the part of the +string. + #. to label x and y axes using xlabel() and ylabel() commands. + #. to add annotations to a plot using annotate() command. + #. to get and set the limits of axes using xlim() and ylim() commands. .. L41 -- cgit