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