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