Difference between revisions of "Python-3.4.3/C2/Embellishing-a-plot/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) (Created page with "{| border=1 |<center>'''Time'''</center> |<center>'''Narration'''</center> |- |00:01 |Hello Friends. Welcome to the tutorial on "'''Embellishing a Plot'''". |- |00:06 |...") |
Sandhya.np14 (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
|00:01 | |00:01 | ||
− | |Hello | + | |Hello friends! Welcome to the tutorial on "'''Embellishing a Plot'''". |
|- | |- | ||
|00:06 | |00:06 | ||
− | |At the end of this tutorial, we will learn to- | + | |At the end of this tutorial, we will learn to- modify the attributes of the '''plot''' -color, line style, linewidth, |
|- | |- | ||
|00:16 | |00:16 | ||
− | | | + | | add a title to the '''plot''' with '''embedded LaTeX''', |
|- | |- | ||
|00:20 | |00:20 | ||
− | | | + | | label '''x '''and '''y axes''', add annotations to the '''plot''', |
|- | |- | ||
|00:26 | |00:26 | ||
− | | | + | | set and get the '''limits '''of '''axes'''. |
|- | |- | ||
|00:30 | |00:30 | ||
− | |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:37 | |00:37 | ||
− | | '''Python 3.4.3''' , '''IPython 5.1.0''' | + | | '''Python 3.4.3''', |
+ | '''IPython 5.1.0''' | ||
|- | |- | ||
|00:43 | |00:43 | ||
− | |To practice this tutorial, you should know how to run basic '''Python ''' | + | |To practice this tutorial, you should know how to '''run''' basic '''Python command'''s on the '''ipython console''' and use the '''Plots''' interactively. |
|- | |- | ||
Line 51: | Line 53: | ||
|- | |- | ||
|01:11 | |01:11 | ||
− | |Let us initialise the '''pylab package''' | + | |Let us initialise the '''pylab package'''. |
|- | |- | ||
|01:15 | |01:15 | ||
− | |Type '''percentage pylab '''and press''' Enter.''' | + | |Type: '''percentage pylab '''and press''' Enter.''' |
|- | |- | ||
|01:21 | |01:21 | ||
− | |We shall first make a simple '''plot''' and start | + | |We shall first make a simple '''plot''' and start modifying it. |
|- | |- | ||
|01:26 | |01:26 | ||
− | |Type '''x = linspace''' inside the ''' | + | |Type: '''x = linspace''' inside the brackets''' minus 2 comma 4 comma 20 '''and press '''Enter.''' |
|- | |- | ||
|01:40 | |01:40 | ||
− | |Then type '''plot''' inside the ''' | + | |Then type '''plot''' inside the brackets '''x comma sin(x) '''and press '''Enter.''' |
|- | |- | ||
Line 95: | Line 97: | ||
|- | |- | ||
|02:20 | |02:20 | ||
− | |Now | + | |Now, plot the same '''sine curve '''with an additional '''color argument'''. |
|- | |- | ||
|02:26 | |02:26 | ||
− | | So we will type '''plot''' inside the ''' | + | | So, we will type '''plot''' inside the brackets '''x comma sin(x) comma''' inside '''inverted commas r '''and press '''Enter.''' |
Here, the '''argument 'r' '''is for red color. | Here, the '''argument 'r' '''is for red color. | ||
Line 109: | Line 111: | ||
|- | |- | ||
|02:50 | |02:50 | ||
− | |Do not close the '''plot | + | |Do not close the '''plot window''', just minimize it. |
|- | |- | ||
Line 121: | Line 123: | ||
|- | |- | ||
|03:05 | |03:05 | ||
− | |So, type '''plot''' inside ''' | + | |So, type '''plot''' inside brackets '''x comma cos(x) comma linewidth is equal to 2 '''and press '''Enter.''' |
|- | |- | ||
Line 133: | Line 135: | ||
|- | |- | ||
| 03:31 | | 03:31 | ||
− | |Here onwards, press the '''Enter''' | + | |Here onwards, press the '''Enter''' key to '''execute''' every '''command''' that we type on the '''Ipython console'''. |
|- | |- | ||
|03:39 | |03:39 | ||
− | |Let us clear the '''plot '''window by typing '''clf(). ''' | + | |Let us first clear the '''plot '''window by typing '''clf(). ''' |
|- | |- | ||
|03:44 | |03:44 | ||
− | |You will again see a blank plot window. | + | |You will again see a blank '''plot window'''. |
|- | |- | ||
|03:48 | |03:48 | ||
− | |Now type''' plot''' inside the ''' | + | |Now type''' plot''' inside the brackets '''x comma sin(x) comma''' inside '''inverted commas b comma linewidth is equal to 3'''. |
|- | |- | ||
Line 161: | Line 163: | ||
|- | |- | ||
| 04:20 | | 04:20 | ||
− | |Now type '''plot''' inside the ''' | + | |Now type '''plot''' inside the brackets '''x comma sin(x) comma''' inside '''inverted commas dot.''' |
|- | |- | ||
Line 173: | Line 175: | ||
|- | |- | ||
|04:40 | |04:40 | ||
− | |Type '''plot question mark '''and press '''Enter''' | + | |Type: '''plot question mark '''and press '''Enter'''. |
|- | |- | ||
Line 181: | Line 183: | ||
|- | |- | ||
|04:52 | |04:52 | ||
− | | | + | |Plot the '''curve''' of '''x verses cos(x)''' in red '''dash line''' and '''linewidth''' 3. |
|- | |- | ||
Line 193: | Line 195: | ||
|- | |- | ||
|05:08 | |05:08 | ||
− | |Now type '''plot''' | + | |Now type '''plot''' inside the brackets '''x comma cos(x) comma''' inside '''inverted commas r hyphen hyphen comma linewidth equals to 3'''. |
|- | |- | ||
Line 201: | Line 203: | ||
|- | |- | ||
| 05:30 | | 05:30 | ||
− | |Now we know how to produce a | + | |Now we know how to produce a bare minimum plot with '''color, style''' and '''thickness'''. |
|- | |- | ||
Line 213: | Line 215: | ||
|- | |- | ||
|05:51 | |05:51 | ||
− | | Now type '''plot''' inside the ''' | + | | Now type '''plot''' inside the brackets '''x comma minus x multiplied by x plus 4 multiplied by x minus 5 comma''' inside '''inverted commas r comma linewidth is equal to 2'''. |
|- | |- | ||
Line 225: | Line 227: | ||
|- | |- | ||
|06:26 | |06:26 | ||
− | |To add a title to the '''plot''', use the '''title | + | |To add a title to the '''plot''', use the '''title''' command. |
|- | |- | ||
|06:31 | |06:31 | ||
− | | So type '''title''' inside the | + | | So, type '''title''' inside the brackets inside '''inverted commas Parabolic function minus x square plus 4x minus 5'''. |
|- | |- | ||
|06:48 | |06:48 | ||
− | |The '''title | + | |The '''title''' command, as you can see, takes a '''string''' as an '''argument.''' |
|- | |- | ||
|06:54 | |06:54 | ||
− | |We can see the''' title''' on the '''plot''' window. But it is not ''' | + | |We can see the''' title''' on the '''plot''' window. But it is not '''format'''ted and does not look clean. |
|- | |- | ||
|07:03 | |07:03 | ||
− | |It would look even more shabby if there were | + | |It would look even more shabby if there were fractions and '''complex function'''s. |
|- | |- | ||
Line 249: | Line 251: | ||
|- | |- | ||
|07:14 | |07:14 | ||
− | |For '''LaTeX''' format, we put a | + | |For '''LaTeX''' format, we put a dollar sign before and after the '''string'''. |
|- | |- | ||
|07:20 | |07:20 | ||
− | |Type '''title''' inside the ''' | + | |Type '''title''' inside the brackets''' r''' inside '''inverted commas Parabolic function dollar minus x square plus 4x minus 5 dollar'''. |
|- | |- | ||
|07:38 | |07:38 | ||
− | |Here | + | |Here, 'r' means that the '''string''' is to be treated as a '''raw string'''. |
|- | |- | ||
Line 265: | Line 267: | ||
|- | |- | ||
|07:49 | |07:49 | ||
− | |As we can see that the '''polynomial''' in the '''title '''is now | + | |As we can see that the '''polynomial''' in the '''title '''is now formatted. |
|- | |- | ||
Line 273: | Line 275: | ||
|- | |- | ||
|08:03 | |08:03 | ||
− | |So we will '''label x''' and '''y axes''' in '''LaTeX style'''. | + | |So, we will '''label x''' and '''y axes''' in '''LaTeX style'''. |
|- | |- | ||
|08:09 | |08:09 | ||
− | |Type '''xlabel''' inside the ''' | + | |Type '''xlabel''' inside the brackets''' r''' inside '''inverted commas dollar x dollar '''and''' ylabel''' inside brackets '''r''' inside '''inverted commas dollar y dollar '''. |
|- | |- | ||
Line 285: | Line 287: | ||
|- | |- | ||
|08:34 | |08:34 | ||
− | |Now we will name the | + | |Now we will name the points considering '''point(2 comma minus 1)''' as '''local maxima'''. |
|- | |- | ||
|08:42 | |08:42 | ||
− | | To name a | + | | To name a point, we use the '''function annotate'''. |
|- | |- | ||
|08:46 | |08:46 | ||
− | |Type '''annotate''' inside the | + | |Type '''annotate''' inside the brackets inside '''inverted commas local maxima comma xy equals to''' inside brackets '''2 comma minus 1'''. |
|- | |- | ||
|09:03 | |09:03 | ||
− | |We can see the '''local maxima''' at point | + | |We can see the '''local maxima''' at point 2 comma minus 1. |
|- | |- | ||
|09:09 | |09:09 | ||
− | |The first '''argument''' in '''annotate | + | |The first '''argument''' in '''annotate''' command is the name of the point. |
|- | |- | ||
|09:15 | |09:15 | ||
− | | The second '''argument''' represents the '''coordinates '''of the | + | | The second '''argument''' represents the '''coordinates '''of the point. |
|- | |- | ||
Line 319: | Line 321: | ||
|- | |- | ||
|09:39 | |09:39 | ||
− | |Then type '''ylim brackets''' '''ylim function''' returns the current '''y-axis limits'''. | + | |Then type '''ylim brackets'''. '''ylim function''' returns the current '''y-axis limits'''. |
|- | |- | ||
| 09:49 | | 09:49 | ||
− | | Set the '''limits of x-axis | + | | Set the '''limits''' of x-axis from '''minus 4''' to '''5''' by typing '''xlim inside the brackets minus 4 comma 5'''. |
|- | |- | ||
|10:02 | |10:02 | ||
− | |Similarly, set the '''limits of y-axis | + | |Similarly, set the '''limits''' of y-axis in a similar manner. |
|- | |- | ||
|10:07 | |10:07 | ||
− | |Type '''ylim''' inside the ''' | + | |Type '''ylim''' inside the brackets '''minus 15 comma 2.''' |
|- | |- | ||
Line 339: | Line 341: | ||
|- | |- | ||
|10:24 | |10:24 | ||
− | | Make an '''annotation''' called "'''root'''" at the ''' | + | | Make an '''annotation''' called "'''root'''" at the point '''(minus 4 comma 0)'''. |
|- | |- | ||
Line 351: | Line 353: | ||
|- | |- | ||
|10:39 | |10:39 | ||
− | |Type '''annotate''' inside the | + | |Type '''annotate''' inside the brackets inside '''inverted commas root comma xy is equal to minus 4 comma 0'''. |
|- | |- | ||
|10:53 | |10:53 | ||
− | |Every '''annotate | + | |Every '''annotate''' command makes a new annotation on the figure. |
|- | |- | ||
|10:59 | |10:59 | ||
− | |This brings us to the end of this | + | |This brings us to the end of this tutorial. In this tutorial, we have learnt to: |
− | + | modify the '''attributes''' of a '''plot''' like '''color, line width, line style''' by passing additional '''arguments''', | |
|- | |- | ||
|11:16 | |11:16 | ||
− | | | + | | add '''title '''to a plot using ''''title''' command, |
|- | |- | ||
|11:20 | |11:20 | ||
− | | | + | | incorporate '''LaTeX''' style formatting by adding a $ sign before and after the '''string''', |
|- | |- | ||
|11:28 | |11:28 | ||
− | | | + | | label '''x''' and '''y axes''' using '''xlabel()''' and '''ylabel()''' commands, |
|- | |- | ||
|11:34 | |11:34 | ||
− | | | + | | add annotations to a plot using '''annotate()''' command, |
|- | |- | ||
|11:39 | |11:39 | ||
− | | | + | | get and set the '''limits''' of axes using '''xlim()''' and '''ylim()''' commands. |
|- | |- | ||
Line 389: | Line 391: | ||
|- | |- | ||
|11:51 | |11:51 | ||
− | | Draw a '''plot''' of '''cosine graph''' between '''minus''' ''' | + | | Draw a '''plot''' of '''cosine graph''' between '''minus 2pi''' to '''2pi''' with line thickness 4. |
|- | |- | ||
|12:00 | |12:00 | ||
− | | Read the documentation and find out, is there a way to modify the | + | | Read the documentation and find out, is there a way to modify the alignment of text in the command '''ylabel'''. |
|- | |- | ||
|12:09 | |12:09 | ||
− | |And the answers are | + | |And the answers are- |
+ | In order to plot a '''cosine graph''' between the points '''minus 2pi''' and '''2pi''' with line thickness 4, we use the '''linspace''' and''' plot''' command as- | ||
'''x equals to linspace inside the brackets minus 2pi comma 2pi.''' | '''x equals to linspace inside the brackets minus 2pi comma 2pi.''' | ||
Line 407: | Line 410: | ||
|- | |- | ||
|12:38 | |12:38 | ||
− | |The answer to the second question is: No. We do not have an option to modify the | + | |The answer to the second question is: |
+ | No. We do not have an option to modify the alignment of text in the command '''ylabel'''. | ||
|- | |- | ||
Line 443: | Line 447: | ||
|- | |- | ||
|13:27 | |13:27 | ||
− | |The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India | + | |The '''Spoken Tutorial''' project is funded by '''NMEICT, MHRD,''' Govt. of India. |
|- | |- | ||
|13:34 | |13:34 | ||
− | |This is Usha from IIT Bombay signing off. Thanks for watching | + | |This is Usha from '''IIT Bombay''', signing off. Thanks for watching. |
|} | |} |
Latest revision as of 13:36, 12 June 2019
00:01 | Hello friends! Welcome to the tutorial on "Embellishing a Plot". |
00:06 | At the end of this tutorial, we will learn to- modify the attributes of the plot -color, line style, linewidth, |
00:16 | add a title to the plot with embedded LaTeX, |
00:20 | label x and y axes, add annotations to the plot, |
00:26 | set and get the limits of axes. |
00:30 | To record this tutorial, I am using:
Ubuntu Linux 14.04 operating system, |
00:37 | Python 3.4.3,
IPython 5.1.0 |
00:43 | To practice this tutorial, you should know how to run basic Python commands on the ipython console and use the Plots interactively. |
00:54 | If not, see the pre-requisite Python tutorials on this website. |
00:59 | Let us start ipython3.
Open the terminal. |
01:05 | Type ipython3 and press Enter. |
01:11 | Let us initialise the pylab package. |
01:15 | Type: percentage pylab and press Enter. |
01:21 | We shall first make a simple plot and start modifying it. |
01:26 | Type: x = linspace inside the brackets minus 2 comma 4 comma 20 and press Enter. |
01:40 | Then type plot inside the brackets x comma sin(x) and press Enter. |
01:49 | We can now see the sine curve in the plot window. |
01:53 | The default colour and thickness of the line is as decided by pylab. |
01:59 | Let us now change the parameters of this curve. |
02:03 | We can pass additional arguments to the plot command to do this. |
02:09 | We shall first clear the plot window by typing clf() in the ipython console. |
02:16 | You can now see a blank plot window. |
02:20 | Now, plot the same sine curve with an additional color argument. |
02:26 | So, we will type plot inside the brackets x comma sin(x) comma inside inverted commas r and press Enter.
Here, the argument 'r' is for red color. |
02:44 | On the plot window, the same sine curve is now seen in red color. |
02:50 | Do not close the plot window, just minimize it. |
02:54 | We can alter the thickness of the line by using the 'linewidth' argument. |
03:00 | This time we will draw the cosine curve on the plot window. |
03:05 | So, type plot inside brackets x comma cos(x) comma linewidth is equal to 2 and press Enter. |
03:18 | A cosine curve with line thickness 2 is produced in the plot window. |
03:24 | Let us now try to plot a sine curve in blue color with linewidth as 3. |
03:31 | Here onwards, press the Enter key to execute every command that we type on the Ipython console. |
03:39 | Let us first clear the plot window by typing clf(). |
03:44 | You will again see a blank plot window. |
03:48 | Now type plot inside the brackets x comma sin(x) comma inside inverted commas b comma linewidth is equal to 3. |
04:03 | A combination of color and linewidth would do the job for us. |
04:08 | To get the plot in dotted style instead of a solid style, put a dot in linestyle. |
04:16 | First, type clf() to clear the plot window. |
04:20 | Now type plot inside the brackets x comma sin(x) comma inside inverted commas dot. |
04:32 | We get the sine curve in dotted style. |
04:36 | Let's see the information of plot. |
04:40 | Type: plot question mark and press Enter. |
04:47 | Pause the video. Try this exercise and then resume the video . |
04:52 | Plot the curve of x verses cos(x) in red dash line and linewidth 3. |
05:00 | Let us switch to the console for the solution. |
05:04 | Type clf() to clear the plot window. |
05:08 | Now type plot inside the brackets x comma cos(x) comma inside inverted commas r hyphen hyphen comma linewidth equals to 3. |
05:25 | We use a combination of linewidth argument and linestyle. |
05:30 | Now we know how to produce a bare minimum plot with color, style and thickness. |
05:38 | Let us look at modifying the plot further. |
05:42 | Let us start with a plot for the function minus x square plus 4x minus 5. |
05:51 | Now type plot inside the brackets x comma minus x multiplied by x plus 4 multiplied by x minus 5 comma inside inverted commas r comma linewidth is equal to 2. |
06:16 | We will see the curve of this equation in the plot window. |
06:21 | But the figure does not have any description describing the plot. |
06:26 | To add a title to the plot, use the title command. |
06:31 | So, type title inside the brackets inside inverted commas Parabolic function minus x square plus 4x minus 5. |
06:48 | The title command, as you can see, takes a string as an argument. |
06:54 | We can see the title on the plot window. But it is not formatted and does not look clean. |
07:03 | It would look even more shabby if there were fractions and complex functions. |
07:09 | Let us write the title in LaTeX format for a neater look. |
07:14 | For LaTeX format, we put a dollar sign before and after the string. |
07:20 | Type title inside the brackets r inside inverted commas Parabolic function dollar minus x square plus 4x minus 5 dollar. |
07:38 | Here, 'r' means that the string is to be treated as a raw string. |
07:45 | It will ignore all escape codes. |
07:49 | As we can see that the polynomial in the title is now formatted. |
07:55 | Although we have title, the plot is not complete without labelling the x and y axes. |
08:03 | So, we will label x and y axes in LaTeX style. |
08:09 | Type xlabel inside the brackets r inside inverted commas dollar x dollar and ylabel inside brackets r inside inverted commas dollar y dollar . |
08:30 | The plot is now almost complete. |
08:34 | Now we will name the points considering point(2 comma minus 1) as local maxima. |
08:42 | To name a point, we use the function annotate. |
08:46 | Type annotate inside the brackets inside inverted commas local maxima comma xy equals to inside brackets 2 comma minus 1. |
09:03 | We can see the local maxima at point 2 comma minus 1. |
09:09 | The first argument in annotate command is the name of the point. |
09:15 | The second argument represents the coordinates of the point. |
09:20 | It is a tuple containing two numbers. The first is x coordinate and second is y coordinate. |
09:29 | Next, type xlim brackets
xlim function returns the current x axis limits. |
09:39 | Then type ylim brackets. ylim function returns the current y-axis limits. |
09:49 | Set the limits of x-axis from minus 4 to 5 by typing xlim inside the brackets minus 4 comma 5. |
10:02 | Similarly, set the limits of y-axis in a similar manner. |
10:07 | Type ylim inside the brackets minus 15 comma 2. |
10:19 | Pause the video. Try this exercise and then resume the video. |
10:24 | Make an annotation called "root" at the point (minus 4 comma 0). |
10:31 | What happens to the first annotation? |
10:35 | Switch to the Ipython console for the solution. |
10:39 | Type annotate inside the brackets inside inverted commas root comma xy is equal to minus 4 comma 0. |
10:53 | Every annotate command makes a new annotation on the figure. |
10:59 | This brings us to the end of this tutorial. In this tutorial, we have learnt to:
modify the attributes of a plot like color, line width, line style by passing additional arguments, |
11:16 | add title to a plot using 'title command, |
11:20 | incorporate LaTeX style formatting by adding a $ sign before and after the string, |
11:28 | label x and y axes using xlabel() and ylabel() commands, |
11:34 | add annotations to a plot using annotate() command, |
11:39 | get and set the limits of axes using xlim() and ylim() commands. |
11:46 | Here are some self assessment questions for you to solve. |
11:51 | Draw a plot of cosine graph between minus 2pi to 2pi with line thickness 4. |
12:00 | Read the documentation and find out, is there a way to modify the alignment of text in the command ylabel. |
12:09 | And the answers are-
In order to plot a cosine graph between the points minus 2pi and 2pi with line thickness 4, we use the linspace and plot command as- x equals to linspace inside the brackets minus 2pi comma 2pi. |
12:31 | plot (x comma cos(x) comma linewidth equals to 4) |
12:38 | The answer to the second question is:
No. We do not have an option to modify the alignment of text in the command ylabel. |
12:48 | Do you have questions on THIS Spoken Tutorial? |
12:51 | Choose the minute and second where you have the question. |
12:55 | Explain your question briefly.
Someone from the FOSSEE team will answer them. Please visit this site. |
13:03 | Do you have any general / technical questions on Python? |
13:08 | Please visit the FOSSEE forum and post your question. |
13:12 | The FOSSEE team coordinates coding of solved examples of popular books. |
13:18 | We give honorarium and certificates for those who do this.
For more details, please visit this website. |
13:27 | The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India. |
13:34 | This is Usha from IIT Bombay, signing off. Thanks for watching. |