author | Anoop Jacob Thomas<anoop@fossee.in> |
Sun, 07 Nov 2010 19:47:26 +0530 | |
changeset 399 | 3c16961361cd |
parent 372 | 8e05616c4102 |
child 416 | 06ac45f4de88 |
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 |
||
47 |
3. We will also see how we can use our graph to indicate Error. |
|
48 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
49 |
One needs to be familiar with the concepts of plotting |
322 | 50 |
mathematical functions in Python. |
51 |
||
52 |
We will use data from a Simple Pendulum Experiment to illustrate our |
|
53 |
points. |
|
54 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
55 |
.. #[[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
|
56 |
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
|
57 |
from here.]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
58 |
|
322 | 59 |
{{{ Simple Pendulum data Slide }}} |
60 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
61 |
.. #[[Anoop: slides are incomplete, work on slides and context |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
62 |
switches]] |
322 | 63 |
|
64 |
||
65 |
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 |
||
68 |
||
69 |
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 |
comma seperated values inside two square brackets. This is also called List |
|
72 |
so to create two sequences |
|
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 |
L,t type in ipython shell. |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
78 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
79 |
.. #[[Anoop: sentence is incomplete, can be removed]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
80 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
81 |
:: |
322 | 82 |
|
83 |
In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9] |
|
84 |
||
85 |
In []: t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94] |
|
86 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
87 |
|
322 | 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.:: |
|
90 |
||
91 |
In []: tsquare=square(t) |
|
92 |
||
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 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
101 |
In []: plot(L,t,'.') |
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 |
||
107 |
In []: clf() |
|
108 |
||
109 |
You can also specify 'o' for big dots.:: |
|
110 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
111 |
In []: plot(L,t,'o') |
322 | 112 |
|
113 |
In []: clf() |
|
114 |
||
115 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
116 |
.. #[[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
|
117 |
plot(L,t,'o')]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
118 |
|
322 | 119 |
{{{ Slide with Error data included }}} |
120 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
121 |
.. #[[Anoop: again slides are incomplete.]] |
322 | 122 |
|
123 |
Now we shall try and take into account error into our plots . The |
|
124 |
Error values for L and T are on your screen.We shall again intialize |
|
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
125 |
the sequence values in the same manner as we did for L and t |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
126 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
127 |
.. #[[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
|
128 |
do]] |
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
129 |
|
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
130 |
:: |
322 | 131 |
|
132 |
In []: delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01] |
|
133 |
||
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 |
||
138 |
Now to plot L vs T^2 with an error bar we use the function errorbar() |
|
139 |
||
140 |
The syntax of the command is as given on the screen. :: |
|
141 |
||
142 |
||
143 |
In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') |
|
144 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
fmt is the format of the plot. |
322 | 148 |
|
149 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
150 |
similarly we can draw the same error bar with big red dots just change |
322 | 151 |
the parameters to fmt to 'ro'. :: |
152 |
||
153 |
In []: clf() |
|
154 |
In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro') |
|
155 |
||
156 |
||
157 |
||
158 |
thats it. you can explore other options to errorbar using the documentation |
|
159 |
of errorbar.:: |
|
160 |
||
161 |
In []: errorbar? |
|
162 |
||
163 |
||
164 |
{{{ Summary Slides }}} |
|
165 |
||
166 |
In this tutorial we have learnt : |
|
167 |
||
168 |
1. How to declare a sequence of number , specifically the kind of sequence we learned was a list. |
|
169 |
||
170 |
2. Plotting experimental data extending our knowledge from mathematical functions. |
|
171 |
||
172 |
3. The various options available for plotting dots instead of lines. |
|
173 |
||
174 |
4. Plotting experimental data such that we can also represent error. We did this using the errorbar() function. |
|
175 |
||
176 |
||
177 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
|
178 |
||
399
3c16961361cd
reviewed plotting-data.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
372
diff
changeset
|
179 |
.. #[[Anoop: again slides are incomplete]] |
322 | 180 |
|
181 |
This tutorial was created as a part of FOSSEE project. |
|
182 |
||
183 |
Hope you have enjoyed and found it useful. |
|
184 |
||
185 |
Thankyou |
|
186 |