plotting-data/script.rst
changeset 416 06ac45f4de88
parent 399 3c16961361cd
child 429 bb6bab81e9f2
child 432 c92662f02209
equal deleted inserted replaced
415:8afa31ae6129 416:06ac45f4de88
    42 1. We will see how we can represent a sequence of numbers in Python. 
    42 1. We will see how we can represent a sequence of numbers in Python. 
    43 
    43 
    44 2. We will also become familiar with  elementwise squaring of such a
    44 2. We will also become familiar with  elementwise squaring of such a
    45 sequence. 
    45 sequence. 
    46 
    46 
    47 3. We will also see how we can use our graph to indicate Error.
    47 3. How to plot data points using python.
       
    48 
       
    49 4. We will also see how we can use our graph to indicate Error.
    48 
    50 
    49 One needs   to  be  familiar  with  the   concepts  of  plotting
    51 One needs   to  be  familiar  with  the   concepts  of  plotting
    50 mathematical functions in Python.
    52 mathematical functions in Python.
    51 
    53 
    52 We will use  data from a Simple Pendulum  Experiment to illustrate our
    54 We will use  data from a Simple Pendulum Experiment to illustrate. 
    53 points. 
       
    54 
    55 
    55 .. #[[Anoop: what do you mean by points here? if you mean the
    56 .. #[[Anoop: what do you mean by points here? if you mean the
    56    points/numbered list in outline slide, then remove the usage point
    57    points/numbered list in outline slide, then remove the usage point
    57    from here.]]
    58    from here.]]
    58 
    59 
    65 As we know for a simple pendulum length,L is directly  proportional to 
    66 As we know for a simple pendulum length,L is directly  proportional to 
    66 the square of time,T. We shall be plotting L and T^2 values.
    67 the square of time,T. We shall be plotting L and T^2 values.
    67 
    68 
    68 
    69 
    69 First  we will have  to initiate L and  T values. We initiate them as sequence 
    70 First  we will have  to initiate L and  T values. We initiate them as sequence 
    70 of values.  To tell ipython a sequence of values we  write the sequence in 
    71 of values.  We define a sequence by comma seperated values inside two square brackets.  
    71 comma  seperated values inside two square brackets.  This is also  called List 
    72 This is also  called List.Lets create two sequences L and t.
    72 so to create two sequences
       
    73 
    73 
    74 .. #[[Anoop: instead of saying "to tell ipython a sequence of values"
    74 .. #[[Anoop: instead of saying "to tell ipython a sequence of values"
    75    and make it complicated, we can tell, we define a sequence as]]
    75    and make it complicated, we can tell, we define a sequence as]]
    76 
    76 
    77 L,t type in ipython shell.
       
    78 
       
    79 .. #[[Anoop: sentence is incomplete, can be removed]]
    77 .. #[[Anoop: sentence is incomplete, can be removed]]
    80 
    78 
    81 ::
    79 {{{ Show the initializing L&T slide }}}
    82 
    80 
    83     In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9]
    81 Type in ipython shell ::
       
    82 
       
    83     L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9]
    84     
    84     
    85     In []: t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94]
    85     t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94]
    86 
    86 
    87  
    87  
    88 To obtain the  square of sequence t we will  use the function square
    88 To obtain the square of sequence t we will use the function square
    89 with argument t.This is saved into the variable tsquare.::
    89 with argument t.This is saved into the variable tsquare.::
    90 
    90 
    91    In []: tsquare=square(t)
    91    tsquare=square(t)
    92   
    92    tsqaure
    93    array([  0.4761, 0.81 , 1.4161,  1.69 , 2.1609,  2.4964, 3.1329, 
    93    array([  0.4761, 0.81 , 1.4161,  1.69 , 2.1609,  2.4964, 3.1329, 
    94    3.3489, 3.7636])
    94    3.3489, 3.7636])
    95 
    95 
    96 .. #[[Anoop: how do you get the array([ 0.4761 ....]) output?]]
    96 .. #[[Anoop: how do you get the array([ 0.4761 ....]) output?]]
    97 
    97 
    98   
    98   
    99 Now to plot L vs T^2 we will simply type ::
    99 Now to plot L vs T^2 we will simply type ::
   100 
   100 
   101   In []: plot(L,t,'.')
   101   plot(L,tsquare,'.')
   102 
   102 
   103 .. #[[Anoop: be consistent with the spacing and all.]]
   103 .. #[[Anoop: be consistent with the spacing and all.]]
   104 
   104 
   105 '.' here represents to plot use small dots for the point. ::
   105 '.' here represents to plot use small dots for the point. ::
   106 
   106 
   107   In []: clf()
   107   clf()
   108 
   108 
   109 You can also specify 'o' for big dots.::
   109 You can also specify 'o' for big dots.::
   110  
   110  
   111   In []: plot(L,t,'o')
   111   plot(L,tsquare,'o')
   112 
   112 
   113   In []: clf()
   113   clf()
   114 
   114 
   115 
   115 
   116 .. #[[Anoop: Make sure code is correct, corrected plot(L,t,o) to
   116 .. #[[Anoop: Make sure code is correct, corrected plot(L,t,o) to
   117    plot(L,t,'o')]]
   117    plot(L,t,'o')]]
   118 
   118 
   119 {{{ Slide with Error data included }}}
   119 
   120 
   120 
   121 .. #[[Anoop: again slides are incomplete.]]
   121 .. #[[Anoop: again slides are incomplete.]]
   122 
   122 
   123 Now we  shall try  and take into  account error  into our plots . The
   123 For any experimental there is always an error in measurements due to
   124 Error values for L and T  are on your screen.We shall again intialize
   124 instrumental and human constaraints.Now we shall try and take into
   125 the sequence values in the same manner as we did for L and t
   125 account error into our plots . The Error values for L and T are on
       
   126 your screen.We shall again intialize the sequence values in the same
       
   127 manner as we did for L and t
   126 
   128 
       
   129 The error data we will use is on your screen.
       
   130 
       
   131 {{{ Show the Adding Error Slide }}}
   127 .. #[[Anoop: give introduction to error and say what we are going to
   132 .. #[[Anoop: give introduction to error and say what we are going to
   128    do]]
   133    do]]
   129 
   134 
   130 ::
   135 ::
   131 
   136 
   132   In []: delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01]
   137     delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01]
   133   
   138     delta_T= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08]
   134   In []: delta_T= [0.04,0.08,0.11,0.05,0.03,0.03,0.01,0.07,0.01]
       
   135 
       
   136 
       
   137   
   139   
   138 Now to plot L vs T^2 with an error bar we use the function errorbar()
   140 Now to plot L vs T^2 with an error bar we use the function errorbar()
   139 
   141 
   140 The syntax of the command is as given on the screen. ::
   142 The syntax of the command is as given on the screen. ::
   141 
   143 
   142     
   144     
   143     In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.')
   145     errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.')
   144 
   146 
   145 This gives a plot with error bar for x and y axis. The dots are of
   147 This gives a plot with error bar for x and y axis. The dots are of
   146 blue color. The parameters xerr and yerr are error on x and y axis and
   148 blue color. The parameters xerr and yerr are error on x and y axis and
   147 fmt is the format of the plot.
   149 fmt is the format of the plot.
   148 
   150 
   149 
   151 
   150 similarly we can draw the same error bar with big red dots just change
   152 similarly we can draw the same error bar with big red dots just change
   151 the parameters to fmt to 'ro'. ::
   153 the parameters to fmt to 'ro'. ::
   152 
   154 
   153     In []: clf()
   155     clf()
   154     In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro')
   156     errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro')
   155 
   157 
   156 
   158 
   157 
   159 
   158 thats it. you can explore other options to errorbar using the documentation 
   160 thats it. you can explore other options to errorbar using the documentation 
   159 of errorbar.::
   161 of errorbar.::
   160 
   162 
   161    In []: errorbar?
   163    errorbar?
   162 
   164 
   163 
   165 
   164 {{{ Summary Slides }}}
   166 {{{ Show Summary Slide }}}
   165 
   167 
   166 In this tutorial we have learnt : 
   168 In this tutorial we have learnt : 
   167 
   169 
   168 1. How to declare a sequence of number , specifically the kind of sequence we learned was a list.
   170 1. How to declare a sequence of number , specifically the kind of sequence we learned was a list.
   169 
   171 
   180 
   182 
   181 This tutorial was created as a part of FOSSEE project.
   183 This tutorial was created as a part of FOSSEE project.
   182 
   184 
   183 Hope you have enjoyed and found it useful.
   185 Hope you have enjoyed and found it useful.
   184 
   186 
   185  Thankyou
   187 Thank You!
   186 
   188