Difference between revisions of "Python-3.4.3/C2/Plotting-Data/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Python/C2/Plotting data /English''' '''Title of script''': '''Plotting data '''
+
'''Python/C2/Plotting data /English'''
 +
 
 +
 
 +
'''Title of script''': '''Plotting data '''
  
 
'''Author: Aditya Palaparthy'''
 
'''Author: Aditya Palaparthy'''
  
'''Keywords: Python, IPython,''' '''plot, title, errorbar'''
+
'''Keywords: Python, IPython,''' '''plot, title, errorbar, video tutorial'''
 
{| style="border-spacing:0;"
 
{| style="border-spacing:0;"
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| <center>'''Visual Cue'''</center>
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| <center>'''Visual Cue'''</center>
Line 12: Line 15:
  
 
containing title, name of the production team along with the logo of MHRD  
 
containing title, name of the production team along with the logo of MHRD  
 
 
  
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Hello Friends. Welcome to the tutorial on "'''Plotting data '''".  
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Hello Friends. Welcome to the tutorial on "'''Plotting data '''".  
Line 25: Line 26:
  
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| In this tutorial, we will learn about
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| In this tutorial, we will learn about
 
  
 
* Define a '''list''' of '''numbers'''.  
 
* Define a '''list''' of '''numbers'''.  
 
* Perform '''element-wise''' squaring of the list.  
 
* Perform '''element-wise''' squaring of the list.  
* '''Plot''' '''data points'''.  
+
* '''Plot data points'''.  
* '''Plot''' '''errorbars'''.  
+
* '''Plot errorbars'''.  
 
+
 
+
  
 
|-
 
|-
Line 46: Line 44:
 
* '''Python 3.4.3'''
 
* '''Python 3.4.3'''
 
* '''IPython 5.1.0'''
 
* '''IPython 5.1.0'''
 
 
  
 
|-
 
|-
Line 83: Line 79:
  
  
Type ''' percent pylab '''and press''' Enter.'''
+
Type '''%pylab '''and press''' Enter.'''
  
 
|-
 
|-
Line 92: Line 88:
  
  
For a '''simple pendulum''' L is '''directly proportional''' to the '''square''' of '''time''' T.  
+
For a '''simple pendulum L''' is '''directly proportional''' to the '''square''' of '''time T'''.  
  
  
We will be '''plotting''' '''L''' and '''T^2 values'''.  
+
We will be '''plotting L''' and '''T square values'''.  
  
 
|-
 
|-
Line 120: Line 116:
 
Type  
 
Type  
  
l''' '''''equal to ''within square brackets ''values ''and press''' Enter'''
+
'''l '''''equal to ''within square brackets ''values ''and press''' Enter'''
  
t''' '''''equal to ''within square brackets the ''values ''and press''' Enter'''
+
'''t '''''equal to ''within square brackets the ''values ''and press''' Enter'''
  
 
|-
 
|-
Line 131: Line 127:
  
  
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now we will obtain '''square''' of '''t '''by using '''function''' '''square'''.  
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now we will obtain '''square''' of '''t '''by using '''function square'''.  
  
 
Type  
 
Type  
  
 
'''tsquare=square '''within parentheses''' t '''and press''' Enter'''
 
'''tsquare=square '''within parentheses''' t '''and press''' Enter'''
 
 
 
  
 
|-
 
|-
Line 144: Line 137:
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now type
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now type
  
'''tsquare and press Enter'''
+
'''tsquare''' and press '''Enter'''
  
 
|-
 
|-
Line 153: Line 146:
  
 
'''3.3489, 3.7636])'''
 
'''3.3489, 3.7636])'''
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see the values of array '''tsquare'''
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see the values of '''array tsquare'''
  
 
|-
 
|-
Line 163: Line 156:
  
  
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now to '''plot L v/s T^2''', we will simply type  
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now to '''plot L versus T square''', we will simply type  
  
 
'''plot '''within parentheses''' I '''''comma '''''tsquare '''''comma'' within single quotes '''dot '''and press''' Enter '''
 
'''plot '''within parentheses''' I '''''comma '''''tsquare '''''comma'' within single quotes '''dot '''and press''' Enter '''
Line 183: Line 176:
  
 
Type '''clf parentheses Enter'''
 
Type '''clf parentheses Enter'''
 
 
 
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| So the plot is clear now
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| So the plot is clear now.
  
 
|-
 
|-
Line 196: Line 186:
  
 
'''plot '''within parentheses''' I '''''comma '''''tsquare '''''comma'' within single quotes '''o '''and press''' Enter'''
 
'''plot '''within parentheses''' I '''''comma '''''tsquare '''''comma'' within single quotes '''o '''and press''' Enter'''
 
 
 
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see the plot with filled circles
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see the plot with filled circles.
  
 
|-
 
|-
Line 208: Line 195:
  
 
Exercise 1  
 
Exercise 1  
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Pause the video. Try this exercise and then resume the video
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Pause the video. Try this exercise and then resume the video.
  
  
Line 217: Line 204:
  
 
Exercise 1 data  
 
Exercise 1 data  
 
 
  
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Use the error data given here for plotting.
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Use the error data given here for plotting.
Line 229: Line 214:
  
 
'''delta_t= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08]'''
 
'''delta_t= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08]'''
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We shall again '''initialize''' the '''sequence values''' in the same manner as we did for l and t.  
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We shall again '''initialize''' the '''sequence values''' in the same manner as we did for '''l''' and '''t'''.  
  
  
Type '''delta_l '''within square bracket the''''' '''values ''and press '''Enter'''
+
Type '''delta underscore l  equal to''' within square bracket the ''values ''and press '''Enter'''
  
'''delta_t '''within square bracket the''''' '''values ''and press '''Enter'''
+
'''delta underscore t '''within square bracket the '' values ''and press '''Enter'''
  
 
|-
 
|-
Line 244: Line 229:
  
  
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now to plot L versus T^2 with an '''error bar,''' we use the '''function''' '''errorbar()'''.  
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Now to plot '''L''' versus '''T''' square with an '''error bar,''' we use the '''function''' '''errorbar()'''.  
  
 
So type,  
 
So type,  
  
errorbar within parentheses '''I '''''comma '''''tsquare '''''comma '''''xerr '''''equalto '''''delta_I '''''comma '''''y_err '''''equalto '''''delta_t '''''comma '''''fmt= '''within single quotes '''bo '''
+
'''errorbar''' within parentheses '''I '''''comma '''''tsquare '''''comma '''''xerr '''''equalto '''''delta underscore I '''''comma '''''y underscore err '''''equalto '''''delta underscore t '''''comma '''''fmt '''equal to within single quotes '''bo '''
  
'''and press Enter'''
+
and press '''Enter'''
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
 
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Show plot window
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see plot L versus T^2 with an '''error bar'''
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| We see plot '''L''' versus '''T square''' with an '''error bar.'''
  
 
|-
 
|-
Line 275: Line 260:
  
  
'''Plot''' the given '''experimental data '''with '''small dots'''. Also include the '''error''' in your '''plot'''.  
+
'''Plot''' the given '''experimental data '''with '''small dots'''.  
 +
 
 +
 
 +
Also include the '''error''' in your '''plot'''.  
  
 
|-
 
|-
Line 298: Line 286:
 
# Use the various '''options''' available for '''plotting''' like '''dots''',''' lines'''.  
 
# Use the various '''options''' available for '''plotting''' like '''dots''',''' lines'''.  
 
# '''Plot experimental data''' such that we can also represent '''error''' by using the '''errorbar() function'''.  
 
# '''Plot experimental data''' such that we can also represent '''error''' by using the '''errorbar() function'''.  
 
 
  
 
|-
 
|-
Line 311: Line 297:
  
  
# '''Square''' the following '''sequence'''.distance_values ''equalto within square brackets'' '''2.1,4.6,8.72,9.03'''  
+
# '''Square''' the following '''sequence'''.distance underscore values ''equal to within square brackets'' '''2.1,4.6,8.72,9.03'''  
 
+
 
# Plot L versus T in '''red pluses'''.  
 
# Plot L versus T in '''red pluses'''.  
 
 
  
 
|-
 
|-
Line 327: Line 310:
  
  
1.To square a sequence of values, we use the function square  
+
1.To square a sequence of values, we use the '''function square'''. So
 +
 
 +
'''square''' ''within parentheses'' '''distance underscore''' ''values''
 +
 
  
square ''within parentheses'' distance_values
+
Answer to the second question
  
2. We pass an additional argument stating the desired parameter  
+
2. We pass an additional '''argument''' stating the desired parameter  
  
plot within parentheses L ''comma'' T ''comma'' within single quotes r ''plus'' for red pluses
+
'''plot''' within parentheses '''L''' ''comma'' '''T''' ''comma'' within single quotes '''r''' ''plus'' for red '''pluses'''
  
 
|-
 
|-
Line 365: Line 351:
  
 
Thank You
 
Thank You
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| This is _________ from IIT Bombay signing off.
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| This is underscore ________ from IIT Bombay signing off.
  
 
Thank You
 
Thank You
  
 
|}
 
|}

Latest revision as of 18:56, 7 September 2017

Python/C2/Plotting data /English


Title of script: Plotting data

Author: Aditya Palaparthy

Keywords: Python, IPython, plot, title, errorbar, video tutorial

Visual Cue
Narration
Show Slide

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

Hello Friends. Welcome to the tutorial on "Plotting data ".
Show Slide

Objectives


In this tutorial, we will learn about
  • Define a list of numbers.
  • Perform element-wise squaring of the list.
  • Plot data points.
  • Plot errorbars.
System Requirements

Ubuntu Linux 14.04


To record this tutorial, I am using
  • Ubuntu Linux 14.04 operating system
  • Python 3.4.3
  • IPython 5.1.0
Show Slide

Pre-requisites


To practise this tutorial, you should know how to
  • run basic Python commands on the ipython console
  • use Plots interactively
  • Embellish a plot

If not, see the relevant Python tutorials on this website.

[Terminal]

ipython3


Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously.


Now, type ipython3 and press Enter.

[IPython console]

%pylab and press Enter.

Let us initialise the pylab package.


Type %pylab and press Enter.

Show Slide

Example - Simple Pendulum

Let us see an example for plotting the data related to a Simple Pendulum.


For a simple pendulum L is directly proportional to the square of time T.


We will be plotting L and T square values.

Show slide

Simple Pendulum Data


Let us use the data shown here for plotting.
[Ipython Terminal]


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]

First let us initiate 'l' and 't' values.

We initiate them as sequence of values. This is also called as List.

Type

l equal to within square brackets values and press Enter

t equal to within square brackets the values and press Enter

[Ipython Terminal]

tsquare=square(t)


Now we will obtain square of t by using function square.

Type

tsquare=square within parentheses t and press Enter

tsquare Now type

tsquare and press Enter

show array in terminal


array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329,

3.3489, 3.7636])

We see the values of array tsquare
[Ipython Terminal]


plot(l,tsquare,'.')


Now to plot L versus T square, we will simply type

plot within parentheses I comma tsquare comma within single quotes dot and press Enter

Show the plot window We see the required plot.
[Ipython Terminal]


clf()

You can also specify 'o' for filled circles.


For this let us clear the plot first.


Type clf parentheses Enter

Show plot window So the plot is clear now.
plot(l,tsquare,'o') Now type,

plot within parentheses I comma tsquare comma within single quotes o and press Enter

Show plot window We see the plot with filled circles.
Show Slide

Exercise 1

Pause the video. Try this exercise and then resume the video.


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

Show Slide

Exercise 1 data

Use the error data given here for plotting.
[Ipython Terminal]


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.


Type delta underscore l equal to within square bracket the values and press Enter

delta underscore t within square bracket the values and press Enter

[Ipython Terminal]


errorbar(l,tsquare,xerr=delta_l, yerr=delta_t, fmt='bo')


Now to plot L versus T square with an error bar, we use the function errorbar().

So type,

errorbar within parentheses I comma tsquare comma xerr equalto delta underscore I comma y underscore err equalto delta underscore t comma fmt equal to within single quotes bo

and press Enter

Show plot window We see plot L versus T square with an error bar.
[Ipython Terminal]


errorbar?

You can explore other options of errorbar using the documentation of errorbar.

That is, errorbar question mark

Show Slide

Exercise 2


Pause the video. Try this exercise and then resume the video.


Plot the given experimental data with small dots.


Also include the error in your plot.

Show Slide

Exercise 2 data

Use the data given here for plotting.
Show Slide

Summary slide


This brings us to the end of this tutorial. In this tutorial, we have learned to,


  1. Declare a list of numbers using the function array.
  1. Perform element-wise squaring using the square function.
  2. Use the various options available for plotting like dots, lines.
  3. Plot experimental data such that we can also represent error by using the errorbar() function.
Show Slide

Evaluation


Here are some self assessment questions for you to solve.


  1. Square the following sequence.distance underscore values equal to within square brackets 2.1,4.6,8.72,9.03
  2. Plot L versus T in red pluses.
Show Slide

Solutions


And the answers,


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

square within parentheses distance underscore values


Answer to the second question

2. We pass an additional argument stating the desired parameter

plot within parentheses L comma T comma within single quotes r plus for red pluses

Show Slide

Forum

Please post your timed queries in this forum.
Show Slide

Fossee Forum

Please post your general queries on Python in this forum.
Show Slide

Textbook Companion

FOSSEE team coordinates the TBC project.
Show Slide

Acknowledgement

Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India.

For more details, visit this website.

Show Slide

Thank You

This is underscore ________ from IIT Bombay signing off.

Thank You

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat, Pratham920