plotui/script.rst
author amit
Thu, 21 Oct 2010 00:22:42 +0530
changeset 342 588b681e70c6
parent 321 2e49b1b72996
child 362 a77a27916f81
permissions -rw-r--r--
Added a few large questions and quickrefs
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
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    29
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    30
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    31
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    32
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
    33
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    34
Now type in your ipython shell ::
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
             In[]: linpace?
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    37
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    38
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    39
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    40
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
    41
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
    42
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
    43
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    44
           In[]: linspace(1,100,100)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    45
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    46
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
    47
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    48
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
    49
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    50
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    51
            In[]: linspace(0,1,200)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    52
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    53
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
    54
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
    55
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
    56
           
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    57
            In[]: p = linspace(-pi,pi,100)
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
'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
    61
.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    62
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    63
If you now ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    64
     
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    65
	   In[]: len(p)
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
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
    68
of a sequence.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    69
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
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
    72
points.  Simply type :: 
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    75
       	  In[]: plot(p,cos(points))
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
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
    78
p.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    79
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
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
    82
plot.::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    83
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    84
           In[]: cosine=cos(points) 
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
	   In[]: plot(p,cosine)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    87
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    90
Now do ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    91
       	 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    92
	   In[]: clf()
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    93
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    94
this will clear the plot.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    95
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    96
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
    97
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
    98
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
    99
plot. ::
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
    	 In []: plot(p,sin(p))
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
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
 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   107
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
   108
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   109
{{{ Show the slide with all the buttons on it }}}
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   110
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   111
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
   112
points at.  
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   113
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   114
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
   115
for saving the file. 
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
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
   118
by the name sin_curve in pdf format.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   119
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   122
{{{ Action corelating with the words }}}
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   123
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   124
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
   125
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   126
Formats like png ,eps ,pdf, ps are available.  
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   127
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   128
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
   129
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   130
{{{ Action corelating with the words  }}}
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   131
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   132
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
   133
region to zoom into.  
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   134
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
   135
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   136
{{{ Action corelating with the words }}}
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   137
 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   138
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
   139
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
   140
back and forward button in the browser.  
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   141
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   142
{{{ Action corelating with the words }}}
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
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
   145
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   146
{{{ Action corelating with the words}}}
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
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
{{{ Summary Slide }}}
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   153
In this tutorial we have looked at 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   154
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   155
1. Starting Ipython with pylab 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   156
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   157
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
   158
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   159
3. Finding length of sequnces using  len.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   160
 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   161
4. Plotting mathematical functions using plot.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   162
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   163
4. Clearing drawing area using clf 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   164
 
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   165
5. Using the UI of plot for studying it better . Using functionalities like save , zoom and moving the plots on x and y axis 
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   166
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   167
321
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   171
{{{ Show the "sponsored by FOSSEE" slide }}}
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
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   175
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
   176
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
 Hope you have enjoyed and found it useful.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   180
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   181
 Thankyou
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   182
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   183
 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   184
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   185
Author              : Amit Sethi
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   186
Internal Reviewer   :
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   187
Internal Reviewer 2 :