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