plotting-data/script.rst
author bhanu
Mon, 08 Nov 2010 01:34:02 +0530
changeset 454 0c69c2b32183
parent 372 8e05616c4102
child 399 3c16961361cd
permissions -rw-r--r--
Language check done for the script `strings`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
372
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     1
.. Objectives
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     2
.. ----------
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     3
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     4
.. By the end of this tutorial, you will be able to
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     5
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     6
.. 1. Defining a list of numbers
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     7
.. 2. Squaring a list of numbers
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     8
.. 3. Plotting data points.
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
     9
.. 4. Plotting errorbars.
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    10
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    11
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    12
.. Prerequisites
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    13
.. -------------
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    14
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    15
..   1. getting started with plotting
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    16
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    17
     
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    18
.. Author              : Amit 
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    19
   Internal Reviewer   :  
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    20
   External Reviewer   :
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    21
   Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
8e05616c4102 Added metadata to plotting-data script
amit
parents: 322
diff changeset
    22
322
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    23
Plotting   Experimental  Data  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    24
=============================   
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    25
Hello  and welcome , this tutorial on  Plotting Experimental data is 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    26
presented by the fossee  team.  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    27
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    28
{{{ Show the slide containing title }}}
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    29
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    30
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    31
{{{ Show the Outline Slide }}}
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    32
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    33
Here  we will discuss plotting  Experimental data. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    34
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    35
1. We will see how we can represent a sequence of numbers in Python. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    36
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    37
2. We will also become fimiliar with  elementwise squaring of such a
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    38
sequence. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    39
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    40
3. We will also see how we can use our graph to indicate Error.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    41
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    42
One needs   to  be  fimiliar  with  the   concepts  of  plotting
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    43
mathematical functions in Python.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    44
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    45
We will use  data from a Simple Pendulum  Experiment to illustrate our
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    46
points. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    47
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    48
{{{ Simple Pendulum data Slide }}} 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    49
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    50
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    51
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    52
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    53
As we know for a simple pendulum length,L is directly  proportional to 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    54
the square of time,T. We shall be plotting L and T^2 values.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    55
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    56
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    57
First  we will have  to initiate L and  T values. We initiate them as sequence 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    58
of values.  To tell ipython a sequence of values we  write the sequence in 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    59
comma  seperated values inside two square brackets.  This is also  called List 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    60
so to create two sequences
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    61
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    62
L,t type in ipython shell. ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    63
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    64
    In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9]
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    65
    
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    66
    In []: t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94]
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    67
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    68
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    69
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    70
To obtain the  square of sequence t we will  use the function square
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    71
with argument t.This is saved into the variable tsquare.::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    72
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    73
   In []: tsquare=square(t)
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    74
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    75
   array([  0.4761, 0.81 , 1.4161,  1.69 , 2.1609,  2.4964, 3.1329, 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    76
   3.3489, 3.7636])
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    77
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    78
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    79
Now to plot L vs T^2 we will simply type ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    80
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    81
  In []: plot(L,t,.)
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    82
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    83
'.' here represents to plot use small dots for the point. ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    84
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    85
  In []: clf()
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    86
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    87
You can also specify 'o' for big dots.::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    88
 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    89
  In []: plot(L,t,o)
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    90
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    91
  In []: clf()
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    92
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    93
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    94
{{{ Slide with Error data included }}}
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    95
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    96
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    97
Now we  shall try  and take into  account error  into our plots . The
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    98
Error values for L and T  are on your screen.We shall again intialize
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
    99
the sequence values in the same manner as we did for L and t ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   100
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   101
  In []: delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01]
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   102
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   103
  In []: delta_T= [0.04,0.08,0.11,0.05,0.03,0.03,0.01,0.07,0.01]
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   104
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   105
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   106
  
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   107
Now to plot L vs T^2 with an error bar we use the function errorbar()
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   108
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   109
The syntax of the command is as given on the screen. ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   110
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   111
    
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   112
    In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.')
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   113
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   114
This gives a  plot with error bar for  x and y axis. The  dots are of blue color. The parameters xerr and yerr are error on x and y axis and fmt is the format of the plot. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   115
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   116
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   117
similarly we can draw the same error bar with big red dots just change 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   118
the parameters to fmt to 'ro'. ::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   119
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   120
    In []: clf()
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   121
    In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro')
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   122
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   123
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   124
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   125
thats it. you can explore other options to errorbar using the documentation 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   126
of errorbar.::
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   127
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   128
   In []: errorbar?
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   129
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   130
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   131
{{{ Summary Slides }}}
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   132
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   133
In this tutorial we have learnt : 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   134
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   135
1. How to declare a sequence of number , specifically the kind of sequence we learned was a list.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   136
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   137
2. Plotting experimental data extending our knowledge from mathematical functions. 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   138
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   139
3. The various options available for plotting dots instead of lines.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   140
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   141
4. Plotting experimental data such that we can also represent error. We did this using the errorbar() function.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   142
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   143
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   144
 {{{ Show the "sponsored by FOSSEE" slide }}}
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   145
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   146
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   147
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   148
This tutorial was created as a part of FOSSEE project.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   149
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   150
Hope you have enjoyed and found it useful.
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   151
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   152
 Thankyou
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   153
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   154
 
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   155
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   156
Author              : Amit Sethi
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   157
Internal Reviewer   :
3cacbcad4c42 Adding plotting data
amit
parents:
diff changeset
   158
Internal Reviewer 2 :