**Narration**
1
00:00:01 --> 00:00:05
Hello friends! Welcome to the **spoken tutorial** on **Subplots**.
2
00:00:06 --> 00:00:13
At the end of this tutorial, you will be able to create and switch between **subplots**.
3
00:00:14 --> 00:00:28
To record this tutorial, I am using:
**Ubuntu Linux 14.04** operating system,

**Python 3.4.3**,

**IPython 5.1.0**.

4
00:00:29 --> 00:00:47
To practise this tutorial, you should know how to:
**run** basic **Python command**s on the **ipython console**,

use **Plots** interactively,

embellish a **plot**.

If not, see the pre-requisite **Python tutorials** on this website.

5
00:00:48 --> 00:01:00
Let us first open the **Terminal **by pressing **Ctrl+Alt+T **keys simultaneously.
Now, type **ipython3** and press **Enter**.

6
00:01:01 --> 00:01:09
Let us initialise the **pylab package**. Type: **percentage pylab **and press** Enter**.
7
00:01:10 --> 00:01:14
To compare two plots, we draw the **plots** in the same plotting area.
8
00:01:15 --> 00:01:23
Let us now create two plots- a **cosine plot** and an **exponential curve** in the same plotting area.
9
00:01:24 --> 00:01:44
Type: **x equals to linspace** inside brackets **0 comma 50 comma 500 **and press **Enter**.
**plot** inside the brackets **x comma cos(x)**.

10
00:01:45 --> 00:02:03
Type: **y equals to linspace** inside brackets **0 comma 5 comma 100.**
**plot** inside brackets **y comma y square.**

11
00:02:04 --> 00:02:12
Here, the two plots have different regular **axes.** So, we cannot draw overlaid plots.
12
00:02:13 --> 00:02:16
In such cases, we can draw **subplots**.
13
00:02:17 --> 00:02:32
We use '**subplot' command** to accomplish this.
Type: **clf()**

**subplot** inside the brackets **2 comma 1 comma 1**.

14
00:02:33 --> 00:02:39
We can see the first **subplot**. The **subplot command** takes three **arguments.**
15
00:02:40 --> 00:02:52
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.

16
00:02:53 --> 00:03:06
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.

17
00:03:07 --> 00:03:18
The last **argument** specifies the serial number for the** subplot**.
Here, we passed 1 as the **argument** which creates the upper subplot.

18
00:03:19 --> 00:03:33
If we **execute** the **subplot command** as-
**subplot** inside the brackets **2 comma 1 comma 2**, the lower subplot is created.

19
00:03:34 --> 00:03:37
Here, we can see now two subplots.
20
00:03:38 --> 00:03:59
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)**.

21
00:04:00 --> 00:04:15
Now, type: **subplot** inside brackets **2 comma 1 comma 2 **
**plot y comma y square**

22
00:04:16 --> 00:04:28
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**.
23
00:04:29 --> 00:04:34
It is clear from the two **subplots** that both have different regular axes.
24
00:04:35 --> 00:04:45
For the **cosine curve, x-axis** varies from 0 to 50 and **y-axis** varies from **minus 1** to **1**.
25
00:04:46 --> 00:04:56
For the **parabolic curve, x-axis** varies from 0 to 5 and **y-axis** varies from 0 to 25.
26
00:04:57 --> 00:04:59
Now clear the **plot window**.
27
00:05:00 --> 00:05:04
Pause the video. Try this exercise and then resume the video.
28
00:05:05 --> 00:05:15
**Pressure, Volume **and** Temperatures **are held by the equation **Pv equals to nRT** where **nR** is a **constant**.
29
00:05:16 --> 00:05:28
Assume **nR equals to 0.01 Joules per Kelvin** and **T equals to 200K**. **V** can be in the range from **21cc to 100cc**.
30
00:05:29 --> 00:05:38
Draw two different plots as** subplots**:
**Pressure v/s Volume plot **and

**Pressure v/s Temperature plot**.

31
00:05:39 --> 00:05:42
Switch to the **terminal** for the solution.
32
00:05:43 --> 00:05:50
To start with, we have been given the range of **Volume** from which we can define the variable **v.**
33
00:05:51 --> 00:06:02
**v equals to linspace** inside brackets **21 comma 100 comma 500**.
34
00:06:03 --> 00:06:23
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)**

35
00:06:24 --> 00:06:37
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. **

36
00:06:38 --> 00:07:01
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)**

37
00:07:02 --> 00:07:07
We have an error now, telling **x** and **y** dimensions don't match.
38
00:07:08 --> 00:07:13
So, we will create same number of points for **temperature.**
39
00:07:14 --> 00:07:26
Type: **t equals to linspace** inside brackets **200 comma 200 comma 500. **
40
00:07:27 --> 00:07:34
Now, we have 500 values in **t **and each with the value 200 **Kelvin**.
41
00:07:35 --> 00:07:47
Plotting this data, we get the required **plot. **
**plot** inside brackets **t comma 2 point 0 divided by v**

42
00:07:48 --> 00:07:55
We can see two **subplots** of **Pressure v/s Volume** and **Pressure v/s Temperature** respectively.
43
00:07:56 --> 00:08:07
This brings us to the end of this tutorial.
In this tutorial, we have learnt to create **subplots **and to **switch** between them.

44
00:08:08 --> 00:08:11
Here are some self assessment questions for you to solve.
45
00:08:12 --> 00:08:35
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**.

46
00:08:36 --> 00:08:47
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**.

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