Python/C2/Plotting-the-data/English

From Script | Spoken-Tutorial
Jump to: navigation, search
Visual Cue Narration
Show Slide 1

Containing title, name of the production team along with the logo of MHRD

Hello Friends and Welcome to this tutorial on "Plotting Experimental data".
Show Slide 2

Learning objectives

At the end of this tutorial, you will be able to,
  1. Define a list of numbers.
  2. perform elementwise squaring of the list.
  3. Plot data points.
  4. plot errorbars.


Show Slide 3

Simple Pendulum data

One needs to be familiar with the concepts of plotting mathematical functions in Python.

We will use data from a Simple Pendulum Experiment to illustrate.

L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9]
T= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94]
As we know for a simple pendulum, length L is directly proportional to the square of time T. We shall be plotting L and T^2 values.

First we will have to initiate L and T values. We initiate them as sequence of values. We define a sequence by comma separated values inside two square brackets. This is also called a List. Let's create two sequences L and t.

Tsquare=square(T)
Tsqaure
array([  0.4761, 0.81 , 1.4161,  1.69 , 2.1609,  2.4964, 3.1329,
3.3489, 3.7636])
To obtain the square of sequence T we will use the function square with argument T.This is saved into the variable Tsquare.
plot(L,Tsquare,'.') Now to plot L vs T^2, we will simply type
clf()
plot(L,Tsquare,'o')
clf()
'.' here displays the plot in a dot pattern. You can also specify 'o' for big dots. For this let us clear the plot first.
Let us move further. For any experimental there is always an error in measurements due to instrumental and human constraints. Now we shall try and take these errors into account in our plots .
Show Slide 4

Assignment 1

Pause the video here, try out the following exercise and resume the video.

Plot the given experimental data with large dots. The data is on your screen.

Show Slide 5

Assessment 1 data

The error data we will use is on your screen.
delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01]
delta_T= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08]
We shall again initialize the sequence values in the same manner as we did for L and T.
errorbar(L,Tsquare,xerr=delta_L, yerr=delta_T, fmt='bo') Now to plot L vs T^2 with an error bar we use the function errorbar().
clf()
errorbar(L,Tsquare,xerr=delta_L, yerr=delta_T, fmt='r.')
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.

similarly we can draw the same error bar with small red dots just change the parameters of fmt to 'r.'.

errorbar? you can explore other options to errorbar using the documentation of errorbar.
Show Slide 6

Assignment 2

Pause the video here, try out the following exercise and resume the video.

Plot the given experimental data with small dots. Also include the error in your plot.

Show Slide 7

Assignment 2 data'

The data is on your screen
Show Slide 8

Summary Slide

This brings us to the end of the end of this tutorial. In this tutorial, we have learnt to,
  1. to declare a sequence of numbers using the function array.
  2. to perform elementwise squaring using the square function.
  3. to use the various options available for plotting like dots,lines.
  4. to Plot experimental data such that we can also represent error by using the errorbar() function.


Show Slide 9

Self assessment questions slide

Here are some self assessment questions for you to solve
  1. Square the following sequence.
    distance_values=[2.1,4.6,8.72,9.03]
  2. Plot L v/s T in red pluses.


Show Slide 10

Solution of self assessment questions on slide

And the answers,

1. To square a sequence of values, we use the function square

square(distance_values)

2. We pass an additional argument stating the desired parameter

plot(L,T,'r+')
Show Slide 11

Acknowledgment slide

Hope you have enjoyed this tutorial and found it useful. Thank You!

Contributors and Content Editors

Chandrika