Difference between revisions of "Python-3.4.3/C2/Multiple-plots/English-timed"
PoojaMoolya (Talk | contribs) (Created page with " {| border=1 | <center>'''Time'''</center> | <center>'''Narration'''</center> |- | 00:01 | Hello Friends. Welcome to the spoken tutorial on "'''Multiple plots'''". |- |...") |
Sandhya.np14 (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Hello | + | | Hello friends! Welcome to the spoken tutorial on "'''Multiple plots'''". |
|- | |- | ||
| 00:07 | | 00:07 | ||
− | | At the end of this tutorial, you will be able to | + | | At the end of this tutorial, you will be able to: |
− | + | draw multiple '''plots''' which are overlaid, | |
|- | |- | ||
| 00:15 | | 00:15 | ||
− | | | + | | use the '''figure''' command, |
|- | |- | ||
| 00:17 | | 00:17 | ||
− | | | + | | use the '''legend''' command, |
|- | |- | ||
| 00:20 | | 00:20 | ||
− | | | + | | switch between the '''plots''' and perform some operations on each of them like saving the '''plot'''s. |
|- | |- | ||
| 00:28 | | 00:28 | ||
− | | To record this tutorial, I am using '''Ubuntu Linux 14.04''' operating system | + | | To record this tutorial, I am using: |
+ | '''Ubuntu Linux 14.04''' operating system, | ||
|- | |- | ||
| 00:36 | | 00:36 | ||
− | | '''Python 3.4.3''' | + | | '''Python 3.4.3''', |
'''IPython 5.1.0''' | '''IPython 5.1.0''' | ||
Line 38: | Line 39: | ||
|- | |- | ||
| 00:42 | | 00:42 | ||
− | | To practise this tutorial, you should know how to use | + | | To practise this tutorial, you should know how to: |
+ | use plots interactively, | ||
|- | |- | ||
| 00:49 | | 00:49 | ||
− | | | + | | embellish a '''plot''', |
− | + | save''' plots'''. | |
|- | |- | ||
| 00:53 | | 00:53 | ||
− | | If not, see the pre-requisite '''Python ''' | + | | If not, see the pre-requisite '''Python tutorials''' on this website. |
|- | |- | ||
Line 66: | Line 68: | ||
|- | |- | ||
| 01:21 | | 01:21 | ||
− | | Let us create set of | + | | Let us create a set of points for our '''plot '''by using the '''command 'linspace''''. |
|- | |- | ||
| 01:29 | | 01:29 | ||
− | | Type '''x equals to linspace''' inside the ''' | + | | Type '''x equals to linspace''' inside the brackets '''0 comma 50 comma 10'''. |
|- | |- | ||
| 01:39 | | 01:39 | ||
− | | Now let us draw a simple '''sine curve''' using these | + | | Now, let us draw a simple '''sine curve''' using these points. |
− | Type '''plot''' inside the ''' | + | Type '''plot''' inside the brackets '''x comma sin(x)'''. |
|- | |- | ||
| 01:51 | | 01:51 | ||
− | | As we can see, this '''sine curve''' is not a | + | | As we can see, this '''sine curve''' is not a smooth curve. What really caused this? |
|- | |- | ||
| 01:59 | | 01:59 | ||
− | | This happened because we selected few | + | | This happened because we selected few points that is 10, for this large interval of 0 to 50. |
|- | |- | ||
| 02:08 | | 02:08 | ||
− | | '''Plot function''' does not | + | | ''''Plot' function''' does not plot the analytical function. |
|- | |- | ||
| 02:12 | | 02:12 | ||
− | | It plots the | + | | It plots the points given by the analytical function. |
|- | |- | ||
| 02:17 | | 02:17 | ||
− | | Now, let us use '''linspace | + | | Now, let us use '''linspace''' command to get 500 points between 0 and 50 and draw the '''sine curve''' again. |
|- | |- | ||
| 02:29 | | 02:29 | ||
− | | Type '''y equals to linspace''' inside the ''' | + | | Type '''y equals to linspace''' inside the brackets '''0 comma 50 comma 500.''' |
|- | |- | ||
| 02:39 | | 02:39 | ||
− | | '''plot''' inside the ''' | + | | '''plot''' inside the brackets '''y comma sin(y)'''. |
|- | |- | ||
| 02:45 | | 02:45 | ||
− | | Now we see a '''sine curve''' with a | + | | Now we see a '''sine curve''' with a smooth curve. |
|- | |- | ||
| 02:50 | | 02:50 | ||
− | | Notice we will also have two | + | | Notice, we will also have two plots one overlaid upon another. |
|- | |- | ||
| 02:56 | | 02:56 | ||
− | | In '''pylab''', by default all the | + | | In '''pylab''', by default, all the plots are overlaid. |
|- | |- | ||
| 03:01 | | 03:01 | ||
− | | To | + | | To distinguish between two overlaid plots we use the ''''legend' command.''' |
|- | |- | ||
| 03:07 | | 03:07 | ||
− | | Type '''legend''' inside the ''' | + | | Type '''legend''' inside the brackets '''square brackets sin(x) comma sin(y).''' |
|- | |- | ||
| 03:16 | | 03:16 | ||
− | | The '''legend | + | | The '''legend''' command takes '''parameter '''as a '''list''' of '''strings.''' |
|- | |- | ||
Line 136: | Line 138: | ||
|- | |- | ||
| 03:27 | | 03:27 | ||
− | | Now we can see the '''legends''' being | + | | Now, we can see the '''legends''' being displayed for the two '''sine curves '''on the plot area. |
|- | |- | ||
| 03:34 | | 03:34 | ||
− | | In the '''IPython terminal''' now type '''clf()''' to clear the '''plot''' | + | | In the '''IPython terminal''', now type '''clf()''' to clear the '''plot window'''. |
|- | |- | ||
Line 148: | Line 150: | ||
|- | |- | ||
| 03:46 | | 03:46 | ||
− | | Draw two | + | | Draw two plots, first plot being a '''parabola''' of the form '''y equals to 4x square''', |
|- | |- | ||
| 03:56 | | 03:56 | ||
− | | and the second being a | + | | and the second being a straight line of the form '''y equals to 2x plus 3''' in the interval '''minus 5''' to '''5'''. |
|- | |- | ||
Line 160: | Line 162: | ||
|- | |- | ||
| 04:11 | | 04:11 | ||
− | | Switch to the terminal for solution. | + | | Switch to the '''terminal''' for solution. |
− | Type '''x is equal to linspace''' inside the ''' | + | Type: '''x is equal to linspace''' inside the brackets '''minus 5 comma 5 comma 100'''. |
|- | |- | ||
| 04:25 | | 04:25 | ||
− | | We can obtain the two | + | | We can obtain the two plots in different colours using the following commands. |
|- | |- | ||
| 04:31 | | 04:31 | ||
− | | '''plot''' inside the ''' | + | | '''plot''' inside the brackets '''x comma 4 multiplied by''' inside the brackets '''x multiplied by x. ''' |
|- | |- | ||
| 04:42 | | 04:42 | ||
− | | '''plot''' inside the ''' | + | | '''plot''' inside the brackets '''x comma 2 multiplied by x plus 3'''. |
|- | |- | ||
Line 182: | Line 184: | ||
|- | |- | ||
| 04:55 | | 04:55 | ||
− | | Type '''legend''' inside the | + | | Type: '''legend''' inside the brackets inside square brackets '''r''' inside '''inverted commas dollar y is equal to 4 x square dollar comma r''' inside '''inverted commas dollar y equals to 2x plus 3 dollar. ''' |
|- | |- | ||
| 05:19 | | 05:19 | ||
Line 189: | Line 191: | ||
|- | |- | ||
| 05:24 | | 05:24 | ||
− | | Next we will learn to | + | | Next we will learn to switch between the plots and perform operations such as saving the plots etc. |
|- | |- | ||
| 05:33 | | 05:33 | ||
− | | Let us see how to accomplish this. But before we move on, let us clear our screen. | + | | Let us see how to accomplish this. But, before we move on, let us clear our '''screen'''. |
− | Type '''clf()''' | + | Type: '''clf()''' |
|- | |- | ||
| 05:43 | | 05:43 | ||
− | | Type '''x equals to linspace''' inside the ''' | + | | Type: '''x equals to linspace''' inside the brackets '''0 comma 50 comma 500'''. |
|- | |- | ||
| 05:53 | | 05:53 | ||
− | | To accomplish more control over | + | | To accomplish more control over individual plots, we use the ''''figure' command. ''' |
− | Type | + | Type: '''figure(1)''' |
− | + | ||
− | '''figure(1)''' | + | |
|- | |- | ||
| 06:03 | | 06:03 | ||
− | | '''plot''' inside the ''' | + | | '''plot''' inside the brackets '''x comma sin(x) comma inside inverted commas b'''. |
|- | |- | ||
Line 219: | Line 219: | ||
|- | |- | ||
| 06:14 | | 06:14 | ||
− | | '''plot''' inside the ''' | + | | '''plot''' inside the brackets '''x comma cos(x) comma''' inside inverted commas '''g'''. |
|- | |- | ||
| 06:24 | | 06:24 | ||
− | | Now we have two | + | | Now, we have two plots, a '''sine curve '''and a '''cosine curve''', in two different figures. |
|- | |- | ||
| 06:33 | | 06:33 | ||
− | | The '''figure | + | | The '''figure''' command takes an '''integer''' as an '''argument. ''' |
− | This is | + | This is the serial number of the plot to select corresponding plot. |
|- | |- | ||
| 06:43 | | 06:43 | ||
− | | All the''' plot | + | | All the''' plot '''commands we '''run''' hereafter are applied to the selected '''plot'''. |
− | In this ''' | + | In this example, '''figure 1''' is the '''sine plot''' and '''figure 2''' is the '''cosine plot'''. |
|- | |- | ||
| 06:56 | | 06:56 | ||
− | | For example, we can '''save''' each | + | | For example, we can '''save''' each plot separately. |
|- | |- | ||
| 07:01 | | 07:01 | ||
− | | Type '''title''' inside | + | | Type: '''title''' inside brackets inside inverted commas '''cos(x)'''. |
|- | |- | ||
| 07:09 | | 07:09 | ||
− | | '''savefig''' inside the | + | | '''savefig''' inside the brackets inside inverted commas '''cosine.png''' |
|- | |- | ||
Line 255: | Line 255: | ||
|- | |- | ||
| 07:21 | | 07:21 | ||
− | | '''title''' inside the | + | | '''title''' inside the brackets inside inverted commas '''sin(x)'''. |
|- | |- | ||
| 07:28 | | 07:28 | ||
− | |'''savefig''' inside the | + | |'''savefig''' inside the brackets inside inverted commas '''sine.png''' |
|- | |- | ||
| 07:36 | | 07:36 | ||
− | | The figures will be saved in current working directory. | + | | The figures will be saved in current '''working directory'''. |
− | Now close both the '''plot''' | + | Now, close both the '''plot windows'''. |
|- | |- | ||
| 07:44 | | 07:44 | ||
− | | Pause the video.Try this exercise and then resume the video. | + | | Pause the video. Try this exercise and then resume the video. |
|- | |- | ||
Line 275: | Line 275: | ||
| Draw a line of the form '''y equals to x''' as one '''figure''' and another line of the form '''y is equal to 2x plus 3'''. | | Draw a line of the form '''y equals to x''' as one '''figure''' and another line of the form '''y is equal to 2x plus 3'''. | ||
− | Save each of them. | + | '''Save''' each of them. |
|- | |- | ||
Line 281: | Line 281: | ||
| Switch to the '''terminal''' for solution. | | Switch to the '''terminal''' for solution. | ||
− | To solve this problem we will use the '''figure | + | To solve this problem, we will use the '''figure''' command to create first plotting area. |
|- | |- | ||
| 08:15 | | 08:15 | ||
− | |Type | + | |Type: '''figure(1) ''' |
− | + | '''x equals to linspace''' inside the brackets '''minus 5 comma 5 comma 100'''. | |
− | + | ||
− | '''x equals to linspace''' inside the ''' | + | |
|- | |- | ||
| 08:29 | | 08:29 | ||
− | |'''plot''' inside the ''' | + | |'''plot''' inside the brackets '''x comma x'''. |
|- | |- | ||
| 08:35 | | 08:35 | ||
− | | Now use the '''figure | + | | Now, use the '''figure''' command to create second plotting area and plot the figure. |
|- | |- | ||
| 08:43 | | 08:43 | ||
− | |Type | + | |Type: '''figure(2) ''' |
− | + | ||
− | '''figure(2) ''' | + | |
− | '''plot''' inside the ''' | + | '''plot''' inside the brackets '''x comma 2x plus 3'''. |
|- | |- | ||
|08:56 | |08:56 | ||
− | | We will | + | | We will '''save''' the figure as follows. |
|- | |- | ||
| 08:59 | | 08:59 | ||
− | |Type | + | |Type: '''figure(1)''' |
− | + | ||
− | '''figure(1)''' | + | |
− | '''savefig''' inside | + | '''savefig''' inside brackets inside inverted commas '''plot1.png''' |
|- | |- | ||
Line 323: | Line 317: | ||
|'''figure(2)''' | |'''figure(2)''' | ||
− | '''savefig''' inside | + | '''savefig''' inside the brackets inside inverted commas '''plot2.png''' |
|- | |- | ||
| 09:23 | | 09:23 | ||
− | | This brings us to the end of this tutorial. In this tutorial, we have learnt to | + | | This brings us to the end of this tutorial. In this tutorial, we have learnt to: |
− | + | draw multiple plots which are overlaid, | |
|- | |- | ||
| 09:33 | | 09:33 | ||
− | | | + | | use the '''figure''' command, |
|- | |- | ||
| 09:35 | | 09:35 | ||
− | | | + | |use the '''legend''' command, |
|- | |- | ||
| 09:38 | | 09:38 | ||
− | | | + | | switch between the plots and perform some operations on each of them like saving the plots. |
|- | |- | ||
| 09:46 | | 09:46 | ||
− | | Here are some self assessment questions for you to solve | + | | Here are some self assessment questions for you to solve- |
− | What '''command''' is used to get individual | + | What '''command''' is used to get individual plots separately? |
|- | |- | ||
Line 355: | Line 349: | ||
|- | |- | ||
| 10:00 | | 10:00 | ||
− | | And the answers | + | | And the answers are- |
− | The '''command "figure()"''' can get us the individual | + | The '''command "figure()"''' can get us the individual plots separately. |
|- | |- | ||
| 10:07 | | 10:07 | ||
− | |The | + | |The '''legend''' command- '''legend''' inside the brackets inside square brackets inside inverted commas '''sin(x) comma inside inverted commas '''cos(x)'''. |
|- | |- | ||
Line 369: | Line 363: | ||
|- | |- | ||
|10:26 | |10:26 | ||
− | | Please post your general queries on Python in this forum. | + | | Please post your general queries on '''Python''' in this forum. |
|- | |- | ||
| 10:31 | | 10:31 | ||
− | | FOSSEE team coordinates the TBC project. | + | | '''FOSSEE''' team coordinates the '''TBC project'''. |
|- | |- | ||
| 10:35 | | 10:35 | ||
− | | Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India. | + | | '''Spoken-tutorial''' is funded by '''NMEICT, MHRD''', Govt. of India. |
For more details, visit this website. | For more details, visit this website. | ||
Line 383: | Line 377: | ||
|- | |- | ||
| 10:45 | | 10:45 | ||
− | | This is Usha from IIT Bombay signing off. Thank You | + | | This is Usha from '''IIT Bombay''', signing off. |
+ | Thank You. | ||
|} | |} |
Latest revision as of 17:53, 12 June 2019
|
|
00:01 | Hello friends! Welcome to the spoken tutorial on "Multiple plots". |
00:07 | At the end of this tutorial, you will be able to:
draw multiple plots which are overlaid, |
00:15 | use the figure command, |
00:17 | use the legend command, |
00:20 | switch between the plots and perform some operations on each of them like saving the plots. |
00:28 | To record this tutorial, I am using:
Ubuntu Linux 14.04 operating system, |
00:36 | Python 3.4.3,
IPython 5.1.0 |
00:42 | To practise this tutorial, you should know how to:
use plots interactively, |
00:49 | embellish a plot,
save plots. |
00:53 | If not, see the pre-requisite Python tutorials on this website. |
00:59 | Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously. |
01:07 | Now, type ipython3 and press Enter. |
01:13 | Let us initialise the pylab package.
Type percentage pylab and press Enter. |
01:21 | Let us create a set of points for our plot by using the command 'linspace'. |
01:29 | Type x equals to linspace inside the brackets 0 comma 50 comma 10. |
01:39 | Now, let us draw a simple sine curve using these points.
Type plot inside the brackets x comma sin(x). |
01:51 | As we can see, this sine curve is not a smooth curve. What really caused this? |
01:59 | This happened because we selected few points that is 10, for this large interval of 0 to 50. |
02:08 | 'Plot' function does not plot the analytical function. |
02:12 | It plots the points given by the analytical function. |
02:17 | Now, let us use linspace command to get 500 points between 0 and 50 and draw the sine curve again. |
02:29 | Type y equals to linspace inside the brackets 0 comma 50 comma 500. |
02:39 | plot inside the brackets y comma sin(y). |
02:45 | Now we see a sine curve with a smooth curve. |
02:50 | Notice, we will also have two plots one overlaid upon another. |
02:56 | In pylab, by default, all the plots are overlaid. |
03:01 | To distinguish between two overlaid plots we use the 'legend' command. |
03:07 | Type legend inside the brackets square brackets sin(x) comma sin(y). |
03:16 | The legend command takes parameter as a list of strings. |
03:21 | Then it assigns strings to plots in the order they were created. |
03:27 | Now, we can see the legends being displayed for the two sine curves on the plot area. |
03:34 | In the IPython terminal, now type clf() to clear the plot window. |
03:41 | Pause the video. Try this exercise and then resume the video. |
03:46 | Draw two plots, first plot being a parabola of the form y equals to 4x square, |
03:56 | and the second being a straight line of the form y equals to 2x plus 3 in the interval minus 5 to 5. |
04:05 | Use legends to indicate what each plot is doing. |
04:11 | Switch to the terminal for solution.
Type: x is equal to linspace inside the brackets minus 5 comma 5 comma 100. |
04:25 | We can obtain the two plots in different colours using the following commands. |
04:31 | plot inside the brackets x comma 4 multiplied by inside the brackets x multiplied by x. |
04:42 | plot inside the brackets x comma 2 multiplied by x plus 3. |
04:50 | Now, we will add a legend to identify the plots. |
04:55 | Type: legend inside the brackets inside square brackets r inside inverted commas dollar y is equal to 4 x square dollar comma r inside inverted commas dollar y equals to 2x plus 3 dollar. |
05:19 | We can see the legend added to the plot. |
05:24 | Next we will learn to switch between the plots and perform operations such as saving the plots etc. |
05:33 | Let us see how to accomplish this. But, before we move on, let us clear our screen.
Type: clf() |
05:43 | Type: x equals to linspace inside the brackets 0 comma 50 comma 500. |
05:53 | To accomplish more control over individual plots, we use the 'figure' command.
Type: figure(1) |
06:03 | plot inside the brackets x comma sin(x) comma inside inverted commas b. |
06:12 | figure(2) |
06:14 | plot inside the brackets x comma cos(x) comma inside inverted commas g. |
06:24 | Now, we have two plots, a sine curve and a cosine curve, in two different figures. |
06:33 | The figure command takes an integer as an argument.
This is the serial number of the plot to select corresponding plot. |
06:43 | All the plot commands we run hereafter are applied to the selected plot.
In this example, figure 1 is the sine plot and figure 2 is the cosine plot. |
06:56 | For example, we can save each plot separately. |
07:01 | Type: title inside brackets inside inverted commas cos(x). |
07:09 | savefig inside the brackets inside inverted commas cosine.png |
07:18 | figure(1) |
07:21 | title inside the brackets inside inverted commas sin(x). |
07:28 | savefig inside the brackets inside inverted commas sine.png |
07:36 | The figures will be saved in current working directory.
Now, close both the plot windows. |
07:44 | Pause the video. Try this exercise and then resume the video. |
07:49 | Draw a line of the form y equals to x as one figure and another line of the form y is equal to 2x plus 3.
Save each of them. |
08:05 | Switch to the terminal for solution.
To solve this problem, we will use the figure command to create first plotting area. |
08:15 | Type: figure(1)
x equals to linspace inside the brackets minus 5 comma 5 comma 100. |
08:29 | plot inside the brackets x comma x. |
08:35 | Now, use the figure command to create second plotting area and plot the figure. |
08:43 | Type: figure(2)
plot inside the brackets x comma 2x plus 3. |
08:56 | We will save the figure as follows. |
08:59 | Type: figure(1)
savefig inside brackets inside inverted commas plot1.png |
09:11 | figure(2)
savefig inside the brackets inside inverted commas plot2.png |
09:23 | This brings us to the end of this tutorial. In this tutorial, we have learnt to:
draw multiple plots which are overlaid, |
09:33 | use the figure command, |
09:35 | use the legend command, |
09:38 | switch between the plots and perform some operations on each of them like saving the plots. |
09:46 | Here are some self assessment questions for you to solve-
What command is used to get individual plots separately? |
09:55 | What will be the command to identify sine and cosine curve? |
10:00 | And the answers are-
The command "figure()" can get us the individual plots separately. |
10:07 | The legend command- legend inside the brackets inside square brackets inside inverted commas sin(x) comma inside inverted commas cos(x). |
10:21 | Please post your timed queries in this forum. |
10:26 | Please post your general queries on Python in this forum. |
10:31 | FOSSEE team coordinates the TBC project. |
10:35 | Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
10:45 | This is Usha from IIT Bombay, signing off.
Thank You. |