Difference between revisions of "Python-3.4.3/C2/Subplots/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border=1 | '''Time''' |'''Narration''' |- |00:01 |Hello Friends. Welcome to the spoken tutorial on '''Subplots'''. |- | 00:06 | At the end of this tutorial, you will be...")
 
 
Line 5: Line 5:
 
|-
 
|-
 
|00:01
 
|00:01
|Hello Friends. Welcome to the spoken tutorial on '''Subplots'''.  
+
|Hello friends! Welcome to the '''spoken tutorial''' on '''Subplots'''.  
  
 
|-
 
|-
Line 13: Line 13:
 
|-
 
|-
 
| 00:14
 
| 00:14
|To record this tutorial, I am using  
+
|To record this tutorial, I am using:
  
'''Ubuntu Linux 14.04''' operating system
+
'''Ubuntu Linux 14.04''' operating system,
  
'''Python 3.4.3'''
+
'''Python 3.4.3''',
  
'''IPython 5.1.0'''
+
'''IPython 5.1.0'''.
  
 
|-
 
|-
 
| 00:29
 
| 00:29
|To practise this tutorial, you should know how to  
+
|To practise this tutorial, you should know how to:
  
Run basic '''Python '''commands on the '''ipython console'''
+
'''run''' basic '''Python command'''s on the '''ipython console''',
  
Use '''Plots''' interactively
+
use '''Plots''' interactively,
  
Embellish a '''plot'''
+
embellish a '''plot'''.
  
If not, see the pre-requisite '''Python '''tutorials on this website.
+
If not, see the pre-requisite '''Python tutorials''' on this website.
  
 
|-
 
|-
Line 40: Line 40:
 
|-
 
|-
 
|01:01
 
|01:01
|Let us initialise the '''pylab package'''. Type '''percentage pylab '''and press''' Enter'''
+
|Let us initialise the '''pylab package'''. Type: '''percentage pylab '''and press''' Enter'''.
  
 
|-
 
|-
 
| 01:10
 
| 01:10
| To compare two '''plots''' we draw the '''plots''' in the same '''plotting area.'''
+
| To compare two plots, we draw the '''plots''' in the same plotting area.
  
 
|-
 
|-
 
| 01:15
 
| 01:15
| Let us now create two '''plots'''- a '''cosine plot''' and an '''exponential curve''' in the same '''plotting area'''.
+
| Let us now create two plots- a '''cosine plot''' and an '''exponential curve''' in the same plotting area.
  
 
|-
 
|-
 
| 01:24
 
| 01:24
| Type
+
| Type: '''x equals to linspace''' inside brackets '''0 comma 50 comma 500 '''and press '''Enter'''.
  
'''x equals to linspace''' inside '''brackets 0 comma 50 comma 500 '''and press '''Enter'''.
+
'''plot''' inside the brackets '''x comma cos(x)'''.
 
+
'''plot''' inside '''brackets x comma cos(x)'''
+
  
 
|-
 
|-
 
| 01:45
 
| 01:45
| Type
+
| Type: '''y equals to linspace''' inside brackets '''0 comma 5 comma 100.'''
 
+
'''plot''' inside brackets '''y comma y square.'''
'''y equals to linspace''' inside '''brackets 0 comma 5 comma 100.'''
+
'''plot''' inside '''brackets y comma y square.'''
+
  
 
|-
 
|-
 
| 02:04
 
| 02:04
| Here the two '''plots''' have different regular '''axes.''' So we cannot draw '''overlaid plots. '''
+
| Here, the two plots have different regular '''axes.''' So, we cannot draw overlaid plots.  
  
 
|-
 
|-
 
| 02:13
 
| 02:13
| In such cases we can draw '''subplots'''.
+
| In such cases, we can draw '''subplots'''.
  
 
|-
 
|-
 
| 02:17
 
| 02:17
| We use '''subplot command''' to accomplish this.
+
| We use ''''subplot' command''' to accomplish this.
 
+
Type
+
  
'''clf()'''
+
Type: '''clf()'''
  
'''subplot''' inside the '''brackets 2 comma 1 comma 1'''
+
'''subplot''' inside the brackets '''2 comma 1 comma 1'''.
  
 
|-
 
|-
 
|02:33
 
|02:33
| We can see the first '''subplot. The '''subplot command''' takes three '''arguments.'''
+
| We can see the first '''subplot'''. The '''subplot command''' takes three '''arguments.'''
  
 
|-
 
|-
 
| 02:40
 
| 02:40
|The first '''argument''' is the number of '''rows''' of '''subplots''' that must be created.
+
|The first '''argument''' is the number of '''row'''s of '''subplots''' that must be created.
  
Here the first '''argument''' is 2, to split the '''plot horizontally'''.
+
Here the first '''argument''' is 2 to split the plot horizontally.
  
 
|-
 
|-
 
| 02:53
 
| 02:53
 
|The second '''argument''' is the number of '''columns''' of '''subplots''' that must be created.  
 
|The second '''argument''' is the number of '''columns''' of '''subplots''' that must be created.  
Here the second '''argument '''is 1.  So '''plot''' will not split '''vertically.'''
+
Here, the second '''argument '''is 1.  So, '''plot''' will not split vertically.
  
 
|-
 
|-
 
| 03:07
 
| 03:07
|The last '''argument''' specifies the '''serial number '''for the''' subplot'''.  
+
|The last '''argument''' specifies the serial number for the''' subplot'''.  
Here we passed 1 as the '''argument''', which creates the '''upper subplot'''
+
Here, we passed 1 as the '''argument''' which creates the upper subplot.
  
 
|-
 
|-
 
| 03:19
 
| 03:19
| If we execute the '''subplot command''' as  
+
| If we '''execute''' the '''subplot command''' as-
  
'''subplot''' inside the '''brackets 2 comma 1 comma 2''' the '''lower subplot''' is created.  
+
'''subplot''' inside the brackets '''2 comma 1 comma 2''', the lower subplot is created.  
  
 
|-
 
|-
 
| 03:34
 
| 03:34
| Here, we can see two '''subplots'''.
+
| Here, we can see now two subplots.
  
 
|-
 
|-
 
| 03:38
 
| 03:38
| Now we can draw '''plots''' in each of the '''subplot area''' using the '''plot command'''.  
+
| Now, we can draw plots in each of the subplot area using the '''plot''' command.  
  
Type
+
Type: '''subplot''' inside brackets '''2 comma 1 comma 1'''.
  
'''subplot''' inside '''brackets 2 comma 1 comma 1'''
+
'''plot''' inside brackets '''x comma cos(x)'''.
 
+
'''plot''' inside '''brackets x comma cos(x)'''
+
  
 
|-
 
|-
 
| 04:00
 
| 04:00
| Now type
+
| Now, type: '''subplot''' inside brackets '''2 comma 1 comma 2 '''
 
+
'''subplot''' inside '''brackets 2 comma 1 comma 2 '''
+
  
 
'''plot y comma y square'''
 
'''plot y comma y square'''
Line 133: Line 123:
 
|-
 
|-
 
|04:16
 
|04:16
| This created two '''plots''' one in each of the''' subplot''' area. The top '''subplot''' holds a '''cosine curve''' And the bottom '''subplot''' holds a '''parabola'''.  
+
| This created two '''plots''', one in each of the''' subplot''' area. The top '''subplot''' holds a '''cosine curve''' and the bottom '''subplot''' holds a '''parabola'''.  
  
 
|-
 
|-
 
| 04:29
 
| 04:29
|It is clear from the two '''subplots''' that both have different '''regular axes'''.  
+
|It is clear from the two '''subplots''' that both have different regular axes.  
  
 
|-
 
|-
 
| 04:35
 
| 04:35
|For the '''cosine curve, x-axis''' varies from 0 to 50 and '''y-axis''' varies from '''minus '''1 to 1.
+
|For the '''cosine curve, x-axis''' varies from 0 to 50 and '''y-axis''' varies from '''minus 1''' to '''1'''.
  
 
|-
 
|-
Line 149: Line 139:
 
|-
 
|-
 
| 04:57
 
| 04:57
| Now clear the plot window
+
| Now clear the '''plot window'''.
  
 
|-
 
|-
 
| 05:00
 
| 05:00
| Pause the video. Try this exercise and then resume the video  
+
| Pause the video. Try this exercise and then resume the video.
  
 
|-
 
|-
 
| 05:05
 
| 05:05
| '''Pressure, Volume '''and''' Temperatures '''are held by the '''equation Pv equals to nRT''' where '''nR''' is a '''constant'''.
+
| '''Pressure, Volume '''and''' Temperatures '''are held by the equation '''Pv equals to nRT''' where '''nR''' is a '''constant'''.
  
 
|-
 
|-
 
| 05:16
 
| 05:16
|  Assume '''nR equals to 0.01 Joules per Kelvin''' and '''T equals to 200K'''. '''V''' can be in the '''range''' from '''21cc to 100cc'''.
+
|  Assume '''nR equals to 0.01 Joules per Kelvin''' and '''T equals to 200K'''. '''V''' can be in the range from '''21cc to 100cc'''.
  
 
|-
 
|-
 
| 05:29
 
| 05:29
| Draw two different''' plots '''as''' subplots''':
+
| Draw two different plots as''' subplots''':
  
 
'''Pressure v/s Volume plot '''and
 
'''Pressure v/s Volume plot '''and
Line 177: Line 167:
 
|-
 
|-
 
| 05:43
 
| 05:43
| To start with, we have been given the '''range''' of '''Volume''' from which we can define the variable '''v.'''
+
| To start with, we have been given the range of '''Volume''' from which we can define the variable '''v.'''
  
 
|-
 
|-
 
| 05:51
 
| 05:51
| '''v equals to linspace''' inside '''brackets 21 comma 100 comma 500'''
+
| '''v equals to linspace''' inside brackets '''21 comma 100 comma 500'''.
  
 
|-
 
|-
 
| 06:03
 
| 06:03
| We can create first '''subplot''' and draw '''Pressure''' v/s '''Volume''' '''graph '''using this '''v'''.  
+
| We can create first '''subplot''' and draw '''Pressure''' v/s '''Volume''' graph using this '''v'''.  
  
 
'''subplot(2 comma 1 comma 1) '''
 
'''subplot(2 comma 1 comma 1) '''
Line 195: Line 185:
 
| We know that '''nRT''' is a '''constant''' which is equal to 2.0  
 
| We know that '''nRT''' is a '''constant''' which is equal to 2.0  
  
since '''nR''' = equals to 0.01 '''Joules per Kelvin'''  and '''T''' equals to 200 '''Kelvin '''
+
since '''nR''' is equal to 0.01 '''Joules per Kelvin'''  and '''T''' equals to 200 '''Kelvin. '''
  
 
|-
 
|-
 
| 06:38
 
| 06:38
| Now we can create the second '''subplot''' and draw the '''Pressure''' v/s '''Temperature plot''' as follows  
+
| Now, we can create the second '''subplot''' and draw the '''Pressure''' v/s '''Temperature plot''' as follows.
  
 
'''subplot(2 comma 1 comma 2)'''
 
'''subplot(2 comma 1 comma 2)'''
Line 207: Line 197:
 
|-
 
|-
 
| 07:02
 
| 07:02
| We have an error now, telling '''x''' and '''y dimensions''' don't match.  
+
| We have an error now, telling '''x''' and '''y''' dimensions don't match.  
  
 
|-
 
|-
 
| 07:08
 
| 07:08
| So we will create same number of '''points''' for '''temperature.'''
+
| So, we will create same number of points for '''temperature.'''
  
 
|-
 
|-
 
| 07:14
 
| 07:14
| Type  
+
| Type: '''t equals to linspace''' inside brackets '''200 comma 200 comma 500. '''
 
+
'''t equals to linspace''' inside '''brackets 200 comma 200 comma 500. '''
+
  
 
|-
 
|-
Line 225: Line 213:
 
|-
 
|-
 
| 07:35
 
| 07:35
| '''Plotting''' this data, we get the required '''plot. '''
+
| Plotting this data, we get the required '''plot. '''
  
'''plot''' inside '''brackets t comma 2 point 0 divided by v'''  
+
'''plot''' inside brackets '''t comma 2 point 0 divided by v'''  
  
 
|-
 
|-
Line 245: Line 233:
 
|-
 
|-
 
| 08:12
 
| 08:12
|1.Which of the following is correct?
+
|1. Which of the following is correct?
  
'''subplot''' inside '''brackets numRows comma numCols, plotNum '''
+
'''subplot''' inside brackets '''numRows comma numCols comma plotNum ''',
  
'''subplot''' inside '''brackets numRows comma numCols '''
+
'''subplot''' inside brackets '''numRows comma numCols ''',
  
'''subplot''' inside '''brackets numCols comma numRows'''
+
'''subplot''' inside brackets '''numCols comma numRows'''.
  
 
|-
 
|-
Line 257: Line 245:
 
| And the answer is first option.
 
| And the answer is first option.
  
1.The''' subplot command''' takes three '''arguments''' namely the number of '''rows''', number of '''columns''' and the '''plot number'''.  
+
1.The''' subplot''' command takes three '''arguments''' namely the number of '''rows''', number of '''columns''' and the '''plot number'''.  
  
 
|-
 
|-
Line 265: Line 253:
 
|-
 
|-
 
| 08:53
 
| 08:53
| Please post your general queries on Python in this forum.
+
| Please post your general queries on '''Python''' in this forum.
  
 
|-
 
|-
 
| 08:59
 
| 08:59
|The FOSSEE team coordinates the TBC project.
+
|The '''FOSSEE''' team coordinates the '''TBC project'''.
  
 
|-
 
|-
 
| 09:04
 
| 09:04
| Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India.For more details, visit this website.
+
| '''Spoken-tutorial''' is funded by '''NMEICT, MHRD''', Govt. of India. For more details, visit this website.
  
 
|-
 
|-
 
| 09:15
 
| 09:15
| This is Usha from IIT Bombay signing off. Thank You.
+
| This is Usha from '''IIT Bombay''', signing off. Thank You.
  
 
|}
 
|}

Latest revision as of 21:37, 12 June 2019

Time Narration
00:01 Hello friends! Welcome to the spoken tutorial on Subplots.
00:06 At the end of this tutorial, you will be able to create and switch between subplots.
00:14 To record this tutorial, I am using:

Ubuntu Linux 14.04 operating system,

Python 3.4.3,

IPython 5.1.0.

00:29 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 pre-requisite Python tutorials on this website.

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

Now, type ipython3 and press Enter.

01:01 Let us initialise the pylab package. Type: percentage pylab and press Enter.
01:10 To compare two plots, we draw the plots in the same plotting area.
01:15 Let us now create two plots- a cosine plot and an exponential curve in the same plotting area.
01:24 Type: x equals to linspace inside brackets 0 comma 50 comma 500 and press Enter.

plot inside the brackets x comma cos(x).

01:45 Type: y equals to linspace inside brackets 0 comma 5 comma 100.

plot inside brackets y comma y square.

02:04 Here, the two plots have different regular axes. So, we cannot draw overlaid plots.
02:13 In such cases, we can draw subplots.
02:17 We use 'subplot' command to accomplish this.

Type: clf()

subplot inside the brackets 2 comma 1 comma 1.

02:33 We can see the first subplot. The subplot command takes three arguments.
02:40 The first argument is the number of rows of subplots that must be created.

Here the first argument is 2 to split the plot horizontally.

02:53 The second argument is the number of columns of subplots that must be created.

Here, the second argument is 1. So, plot will not split vertically.

03:07 The last argument specifies the serial number for the subplot.

Here, we passed 1 as the argument which creates the upper subplot.

03:19 If we execute the subplot command as-

subplot inside the brackets 2 comma 1 comma 2, the lower subplot is created.

03:34 Here, we can see now two subplots.
03:38 Now, we can draw plots in each of the subplot area using the plot command.

Type: subplot inside brackets 2 comma 1 comma 1.

plot inside brackets x comma cos(x).

04:00 Now, type: subplot inside brackets 2 comma 1 comma 2

plot y comma y square

04:16 This created two plots, one in each of the subplot area. The top subplot holds a cosine curve and the bottom subplot holds a parabola.
04:29 It is clear from the two subplots that both have different regular axes.
04:35 For the cosine curve, x-axis varies from 0 to 50 and y-axis varies from minus 1 to 1.
04:46 For the parabolic curve, x-axis varies from 0 to 5 and y-axis varies from 0 to 25.
04:57 Now clear the plot window.
05:00 Pause the video. Try this exercise and then resume the video.
05:05 Pressure, Volume and Temperatures are held by the equation Pv equals to nRT where nR is a constant.
05:16 Assume nR equals to 0.01 Joules per Kelvin and T equals to 200K. V can be in the range from 21cc to 100cc.
05:29 Draw two different plots as subplots:

Pressure v/s Volume plot and

Pressure v/s Temperature plot.

05:39 Switch to the terminal for the solution.
05:43 To start with, we have been given the range of Volume from which we can define the variable v.
05:51 v equals to linspace inside brackets 21 comma 100 comma 500.
06:03 We can create first subplot and draw Pressure v/s Volume graph using this v.

subplot(2 comma 1 comma 1)

plot(v comma 2 point 0 by v)

06:24 We know that nRT is a constant which is equal to 2.0

since nR is equal to 0.01 Joules per Kelvin and T equals to 200 Kelvin.

06:38 Now, we can create the second subplot and draw the Pressure v/s Temperature plot as follows.

subplot(2 comma 1 comma 2)

plot(200 comma 2 point 0 divided by v)

07:02 We have an error now, telling x and y dimensions don't match.
07:08 So, we will create same number of points for temperature.
07:14 Type: t equals to linspace inside brackets 200 comma 200 comma 500.
07:27 Now, we have 500 values in t and each with the value 200 Kelvin.
07:35 Plotting this data, we get the required plot.

plot inside brackets t comma 2 point 0 divided by v

07:48 We can see two subplots of Pressure v/s Volume and Pressure v/s Temperature respectively.
07:56 This brings us to the end of this tutorial.

In this tutorial, we have learnt to create subplots and to switch between them.

08:08 Here are some self assessment questions for you to solve.
08:12 1. Which of the following is correct?

subplot inside brackets numRows comma numCols comma plotNum ,

subplot inside brackets numRows comma numCols ,

subplot inside brackets numCols comma numRows.

08:36 And the answer is first option.

1.The subplot command takes three arguments namely the number of rows, number of columns and the plot number.

08:48 Please post your timed queries in this forum.
08:53 Please post your general queries on Python in this forum.
08:59 The FOSSEE team coordinates the TBC project.
09:04 Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India. For more details, visit this website.
09:15 This is Usha from IIT Bombay, signing off. Thank You.

Contributors and Content Editors

Pratik kamble, Sandhya.np14