author | Amit Sethi |
Wed, 10 Nov 2010 02:12:09 +0530 | |
changeset 434 | c8ffd52305ff |
parent 432 | c92662f02209 |
parent 429 | bb6bab81e9f2 |
permissions | -rw-r--r-- |
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 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
19 |
Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> |
372 | 20 |
External Reviewer : |
21 |
Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
|
22 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
23 |
.. #[[Anoop: Add quickref]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
24 |
.. #[[Anoop: Slides are incomplete, add summary slide, thank you slide |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
25 |
etc.]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
26 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
27 |
=============================== |
322 | 28 |
Plotting Experimental Data |
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
29 |
=============================== |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
30 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
31 |
{{{ Show the slide containing title }}} |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
32 |
|
322 | 33 |
Hello and welcome , this tutorial on Plotting Experimental data is |
34 |
presented by the fossee team. |
|
35 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
36 |
{{{ Show the Outline Slide }}} |
322 | 37 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
38 |
.. #[[Anoop: outline slide is missing]] |
322 | 39 |
|
40 |
Here we will discuss plotting Experimental data. |
|
41 |
||
42 |
1. We will see how we can represent a sequence of numbers in Python. |
|
43 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
44 |
2. We will also become familiar with elementwise squaring of such a |
322 | 45 |
sequence. |
46 |
||
416 | 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. |
|
322 | 50 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
51 |
One needs to be familiar with the concepts of plotting |
322 | 52 |
mathematical functions in Python. |
53 |
||
416 | 54 |
We will use data from a Simple Pendulum Experiment to illustrate. |
322 | 55 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
56 |
.. #[[Anoop: what do you mean by points here? if you mean the |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
57 |
points/numbered list in outline slide, then remove the usage point |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
58 |
from here.]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
59 |
|
322 | 60 |
{{{ Simple Pendulum data Slide }}} |
61 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
62 |
.. #[[Anoop: slides are incomplete, work on slides and context |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
63 |
switches]] |
322 | 64 |
|
65 |
||
66 |
As we know for a simple pendulum length,L is directly proportional to |
|
67 |
the square of time,T. We shall be plotting L and T^2 values. |
|
68 |
||
69 |
||
70 |
First we will have to initiate L and T values. We initiate them as sequence |
|
416 | 71 |
of values. We define a sequence by comma seperated values inside two square brackets. |
72 |
This is also called List.Lets create two sequences L and t. |
|
322 | 73 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
74 |
.. #[[Anoop: instead of saying "to tell ipython a sequence of values" |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
75 |
and make it complicated, we can tell, we define a sequence as]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
76 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
77 |
.. #[[Anoop: sentence is incomplete, can be removed]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
78 |
|
416 | 79 |
{{{ Show the initializing L&T slide }}} |
80 |
||
81 |
Type in ipython shell :: |
|
322 | 82 |
|
416 | 83 |
L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9] |
322 | 84 |
|
416 | 85 |
t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94] |
322 | 86 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
87 |
|
416 | 88 |
To obtain the square of sequence t we will use the function square |
322 | 89 |
with argument t.This is saved into the variable tsquare.:: |
90 |
||
416 | 91 |
tsquare=square(t) |
92 |
tsqaure |
|
322 | 93 |
array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329, |
94 |
3.3489, 3.7636]) |
|
95 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
96 |
.. #[[Anoop: how do you get the array([ 0.4761 ....]) output?]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
97 |
|
322 | 98 |
|
99 |
Now to plot L vs T^2 we will simply type :: |
|
100 |
||
416 | 101 |
plot(L,tsquare,'.') |
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
102 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
103 |
.. #[[Anoop: be consistent with the spacing and all.]] |
322 | 104 |
|
105 |
'.' here represents to plot use small dots for the point. :: |
|
106 |
||
416 | 107 |
clf() |
322 | 108 |
|
109 |
You can also specify 'o' for big dots.:: |
|
110 |
||
416 | 111 |
plot(L,tsquare,'o') |
322 | 112 |
|
416 | 113 |
clf() |
322 | 114 |
|
115 |
||
432 | 116 |
Following are exercises that you must do. |
117 |
||
118 |
%% %% Plot the given experimental data with large dots.The data is |
|
119 |
on your screen. |
|
120 |
||
121 |
%% %% Plot the given experimental data with small dots. |
|
122 |
The data is on your screen |
|
123 |
||
124 |
||
125 |
Please, pause the video here. Do the exercises and then continue. |
|
126 |
||
127 |
||
128 |
||
129 |
||
130 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
131 |
.. #[[Anoop: Make sure code is correct, corrected plot(L,t,o) to |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
132 |
plot(L,t,'o')]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
133 |
|
416 | 134 |
|
322 | 135 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
136 |
.. #[[Anoop: again slides are incomplete.]] |
322 | 137 |
|
416 | 138 |
For any experimental there is always an error in measurements due to |
139 |
instrumental and human constaraints.Now we shall try and take into |
|
140 |
account error into our plots . The Error values for L and T are on |
|
141 |
your screen.We shall again intialize the sequence values in the same |
|
142 |
manner as we did for L and t |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
143 |
|
416 | 144 |
The error data we will use is on your screen. |
145 |
||
146 |
{{{ Show the Adding Error Slide }}} |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
147 |
.. #[[Anoop: give introduction to error and say what we are going to |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
148 |
do]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
149 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
150 |
:: |
322 | 151 |
|
416 | 152 |
delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01] |
153 |
delta_T= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08] |
|
322 | 154 |
|
155 |
Now to plot L vs T^2 with an error bar we use the function errorbar() |
|
156 |
||
157 |
The syntax of the command is as given on the screen. :: |
|
158 |
||
159 |
||
416 | 160 |
errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') |
322 | 161 |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
162 |
This gives a plot with error bar for x and y axis. The dots are of |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
163 |
blue color. The parameters xerr and yerr are error on x and y axis and |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
164 |
fmt is the format of the plot. |
322 | 165 |
|
166 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
167 |
similarly we can draw the same error bar with big red dots just change |
322 | 168 |
the parameters to fmt to 'ro'. :: |
169 |
||
416 | 170 |
clf() |
171 |
errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro') |
|
322 | 172 |
|
173 |
||
174 |
||
175 |
thats it. you can explore other options to errorbar using the documentation |
|
176 |
of errorbar.:: |
|
177 |
||
416 | 178 |
errorbar? |
322 | 179 |
|
432 | 180 |
Following is an exercise that you must do. |
181 |
||
182 |
%% %% Plot the given experimental data with large green dots.Also include |
|
183 |
the error in your plot. |
|
184 |
||
185 |
Please, pause the video here. Do the exercise and then continue. |
|
186 |
||
187 |
||
188 |
||
189 |
||
190 |
||
191 |
||
322 | 192 |
|
416 | 193 |
{{{ Show Summary Slide }}} |
322 | 194 |
|
432 | 195 |
In this tutorial we have learnt : |
322 | 196 |
|
434 | 197 |
|
322 | 198 |
|
429 | 199 |
1. How to declare a sequence of numbers. |
322 | 200 |
|
429 | 201 |
2. Plotting experimental data. |
322 | 202 |
|
432 | 203 |
#. The various options available for plotting dots instead of lines. |
322 | 204 |
|
434 | 205 |
#. Plotting experimental data such that we can also represent error. |
206 |
||
322 | 207 |
|
208 |
||
209 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
|
210 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
211 |
.. #[[Anoop: again slides are incomplete]] |
322 | 212 |
|
213 |
This tutorial was created as a part of FOSSEE project. |
|
214 |
||
215 |
Hope you have enjoyed and found it useful. |
|
216 |
||
416 | 217 |
Thank You! |
322 | 218 |