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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border=1 | <center>'''Time'''</center> | <center>'''Narration'''</center> |- | 00:01 | Hello Friends. Welcome to the spoken tutorial on "'''Multiple plots'''". |- |...")
 
Line 120: Line 120:
 
|-  
 
|-  
 
| 03:01
 
| 03:01
| To '''distinguish''' between two '''overlaid plots''' we use the '''legend command.'''  
+
| To distinguish between two '''overlaid plots''' we use the '''legend command.'''  
  
 
|-  
 
|-  
Line 235: Line 235:
 
| All the''' plot commands '''we run hereafter are applied to the selected '''plot'''.  
 
| 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'''.  
+
In this example, '''figure''' 1 is the '''sine plot''' and '''figure''' 2 is the '''cosine''' '''plot'''.  
  
 
|-  
 
|-  

Revision as of 10:52, 11 June 2019

Time
Narration
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 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 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,

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

Contributors and Content Editors

PoojaMoolya, Sandhya.np14