using-plot-interactively/script.rst
changeset 409 43a24f7ab183
parent 362 a77a27916f81
child 467 501383b753c1
equal deleted inserted replaced
408:8f4c369a41f1 409:43a24f7ab183
       
     1 .. Objectives
       
     2 .. ----------
       
     3 
       
     4 .. By the end of this tutorial you will --
       
     5 
       
     6 .. 1. Create simple plots of mathematical functions
       
     7 .. #. Use the Figure window to study plots better
       
     8 
       
     9 
       
    10 
       
    11 .. Prerequisites
       
    12 .. -------------
       
    13 
       
    14 .. Installation of required tools
       
    15 .. Ipython
       
    16      
       
    17 .. Author              : Amit Sethi
       
    18    Internal Reviewer   : 
       
    19    External Reviewer   :
       
    20    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
       
    21 
       
    22 Script
       
    23 -------
       
    24 
       
    25 
       
    26 Hello and welcome to the tutorial on creating simple plots using
       
    27 Python.This tutorial is presented by the Fossee group.  
       
    28 {{{ Show the Title Slide }}} 
       
    29 
       
    30 I hope you have IPython running on your computer.
       
    31 
       
    32 In this tutorial we will look at plot command and also how to study
       
    33 the plot using the UI.
       
    34 
       
    35 {{{ Show Outline Slide }}}
       
    36 
       
    37 Lets start ipython on your shell, type :: 
       
    38 
       
    39       $ipython -pylab
       
    40 
       
    41 
       
    42 Pylab is a python library which provides plotting functionality.It
       
    43 also provides many other important mathematical and scientific
       
    44 functions. After running IPython -pylab in your shell if at the top of
       
    45 the result of this command, you see something like ::
       
    46  
       
    47 
       
    48    `ERROR: matplotlib could NOT be imported!  Starting normal
       
    49       IPython.`
       
    50 
       
    51 
       
    52 {{{ Slide with Error written on it }}}
       
    53 
       
    54 
       
    55 
       
    56 
       
    57 Then you have to install matplotlib and run this command again.
       
    58 
       
    59 Now type in your ipython shell ::
       
    60 
       
    61              In[]: linpace?
       
    62 
       
    63 
       
    64 
       
    65 as the documentation says, it returns `num` evenly spaced samples,
       
    66 calculated over the interval start and stop.  To illustrate this, lets
       
    67 do it form 1 to 100 and try 100 points.  ::
       
    68 
       
    69            In[]: linspace(1,100,100)
       
    70 
       
    71 As you can see a sequence of numbers from 1 to 100 appears.
       
    72 
       
    73 Now lets try 200 points between 0 and 1 you do this by typing ::
       
    74 
       
    75 
       
    76             In[]: linspace(0,1,200)
       
    77 
       
    78 0 for start , 1 for stop and 200 for no of points.  In linspace 
       
    79 the start and stop points can be integers, decimals , or
       
    80 constants. Let's try and get 100 points between -pi to pi. Type ::
       
    81            
       
    82             In[]: p = linspace(-pi,pi,100)
       
    83 
       
    84 
       
    85 'pi' here is constant defined by pylab. Save this to the variable, p
       
    86 .
       
    87 
       
    88 If you now ::
       
    89      
       
    90 	   In[]: len(p)
       
    91 
       
    92 You will get the no. of points. len function gives the no of elements
       
    93 of a sequence.
       
    94 
       
    95 
       
    96 Let's try and plot a cosine curve between -pi and pi using these
       
    97 points.  Simply type :: 
       
    98 
       
    99 
       
   100        	  In[]: plot(p,cos(points))
       
   101 
       
   102 Here cos(points) gets the cosine value at every corresponding point to
       
   103 p.
       
   104 
       
   105 
       
   106 We can also save cos(points) to variable cosine and plot it using
       
   107 plot.::
       
   108 
       
   109            In[]: cosine=cos(points) 
       
   110 
       
   111 	   In[]: plot(p,cosine)
       
   112 
       
   113  
       
   114 
       
   115 Now do ::
       
   116        	 
       
   117 	   In[]: clf()
       
   118 
       
   119 this will clear the plot.
       
   120 
       
   121 This is done because any other plot we try to make shall come on the
       
   122 same drawing area. As we do not wish to clutter the area with
       
   123 overlaid plots , we just clear it with clf().  Now lets try a sine
       
   124 plot. ::
       
   125 
       
   126 
       
   127     	 In []: plot(p,sin(p))
       
   128 
       
   129 
       
   130 
       
   131  
       
   132 The Window on which the plot appears can be used to study it better.
       
   133 
       
   134 {{{ Show the slide with all the buttons on it }}}
       
   135 
       
   136 First of all moving the mouse around gives us the point where mouse
       
   137 points at.  
       
   138 
       
   139 Also we have some buttons the right most among them is
       
   140 for saving the file. 
       
   141 
       
   142 Just click on it specifying the name of the file.  We will save the plot 
       
   143 by the name sin_curve in pdf format.
       
   144 
       
   145 
       
   146 
       
   147 {{{ Action corelating with the words }}}
       
   148 
       
   149 As you can see I can specify format of file from the dropdown.
       
   150 
       
   151 Formats like png ,eps ,pdf, ps are available.  
       
   152 
       
   153 Left to the save button is the slider button to specify the margins.  
       
   154 
       
   155 {{{ Action corelating with the words  }}}
       
   156 
       
   157 Left to this is zoom button to zoom into the plot. Just specify the 
       
   158 region to zoom into.  
       
   159 The button left to it can be used to move the axes of the plot.  
       
   160 
       
   161 {{{ Action corelating with the words }}}
       
   162  
       
   163 The next two buttons with a left and right arrow icons change the state of the 
       
   164 plot and take it to the previous state it was in. It more or less acts like a
       
   165 back and forward button in the browser.  
       
   166 
       
   167 {{{ Action corelating with the words }}}
       
   168 
       
   169 The last one is 'home' referring to the initial plot.
       
   170 
       
   171 {{{ Action corelating with the words}}}
       
   172 
       
   173 
       
   174 
       
   175 {{{ Summary Slide }}}
       
   176 
       
   177 
       
   178 In this tutorial we have looked at 
       
   179 
       
   180 1. Starting Ipython with pylab 
       
   181 
       
   182 2. Using linspace function to create `num` equaly spaced points in a region.
       
   183 
       
   184 3. Finding length of sequnces using  len.
       
   185  
       
   186 4. Plotting mathematical functions using plot.
       
   187 
       
   188 4. Clearing drawing area using clf 
       
   189  
       
   190 5. Using the UI of plot for studying it better . Using functionalities like save , zoom and moving the plots on x and y axis 
       
   191 
       
   192 
       
   193  
       
   194 
       
   195 
       
   196 {{{ Show the "sponsored by FOSSEE" slide }}}
       
   197 
       
   198  
       
   199 
       
   200 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
       
   201 
       
   202  
       
   203 
       
   204  Hope you have enjoyed and found it useful.
       
   205 
       
   206  Thankyou
       
   207 
       
   208  
       
   209 
       
   210 Author              : Amit Sethi
       
   211 Internal Reviewer   :
       
   212 Internal Reviewer 2 :