Difference between revisions of "Python/C2/Embellishing-a-plot/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Timing !Narration |- | 0:00 | Welcome to the tutorial on "Embellishing a Plot". |- | 0:06 | At the end of this tutorial, you will be able to, # Modify the attrib…')
 
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
 
+
00:00
0:00
+
|Hello friends. Welcome to the tutorial on '''Embellishing a Plot'''.
| Welcome to the tutorial on "Embellishing a Plot".
+
  
 
|-
 
|-
| 0:06
+
| 00:06
| At the end of this tutorial, you will be able to,
+
| At the end of this tutorial, you will be able to-
 
+
Modify the attributes of the plot -- color, line style, line width.
# Modify the attributes of the plot -- color, line style,linewidth.
+
Add a title to the plot with embedded '''LaTeX'''.
# Add a title to the plot with embedded LaTeX.
+
Label X and Y axes.
# Label x and y axes.
+
Add annotations to the plot.
# Add annotations to the plot.
+
Set and Get the limits of axes.
# Set and Get the limits of axes.
+
 
+
 
+
  
 
|-
 
|-
| 0:27
+
| 00:27
| So, Before beginning this tutorial,we would suggest you to complete the tutorial on "Using plot interactively".
+
| So, before beginning this tutorial, we would suggest you to complete the tutorial on '''Using plot interactively'''.
  
 
|-
 
|-
| 0:34
+
| 00:34
| so,let us start ipython with pylab loaded, open the terminal and type ipython hyphen pylab.
+
| So, let us start '''ipython''' with '''pylab''' loaded. Open the terminal and type: '''ipython hyphen pylab'''.
  
 
|-
 
|-
| 0:48
+
| 00:48
| We shall first make a simple plot and start decorating it.
+
| We shall first make a simple '''plot''' and start decorating it.
  
 
|-
 
|-
| 0:54
+
| 00:54
|So type x is equal to linspace within brackets -2,4,20
+
|So, type: '''x is equal to linspace within brackets '''-2, 4, 20'''.
  
 
|-
 
|-
| 1:06
+
| 01:06
|then type plot(x,sin(x))
+
|Then type plot(x, sin(x)).
  
 
|-
 
|-
| 1:15
+
| 01:15
| As we can see, the default colour and the default thickness of the line is as decided by pylab.
+
| As we can see, the default colour and the default thickness of the line is as decided by '''pylab'''.
  
 
|-
 
|-
| 1:23
+
| 01:23
 
| Wouldn't it be nice if we could control these parameters in the plot?  
 
| Wouldn't it be nice if we could control these parameters in the plot?  
  
 
|-
 
|-
| 1:28
+
| 01:28
 
|This is possible by passing additional arguments to the plot command.
 
|This is possible by passing additional arguments to the plot command.
  
 
|-
 
|-
| 1:33
+
| 01:33
 
| We shall first clear the figure and plot the same by passing the additional color argument.
 
| We shall first clear the figure and plot the same by passing the additional color argument.
  
 
|-
 
|-
| 1:39
+
| 01:39
 
| Pass the argument 'r' for red color.
 
| Pass the argument 'r' for red color.
  
 
|-
 
|-
| 1:44
+
| 01:44
| So type clf, then plot within brackets x,sin(x),within single quotes r.
+
| So, type '''clf''', then '''plot''' within brackets '''x, sin(x)''', within single quotes r.
  
 
|-
 
|-
2:13
+
02:13
 
| The same plot is seen in red color.
 
| The same plot is seen in red color.
  
 
|-
 
|-
| 2:16
+
| 02:16
| The thickness of the line can be altered by 'linewidth' argument.
+
| The thickness of the line can be altered by ''''linewidth'''' argument.
  
 
|-
 
|-
| 2:20
+
| 02:20
|So type plot within brackets x,cos(x),linewidth is equal to 2
+
|So, type: '''plot''' within brackets '''x, cos(x), linewidth is equal to 2'''.
  
 
|-
 
|-
| 2:34
+
| 02:34
 
|Now, a plot with line thickness 2 is produced.
 
|Now, a plot with line thickness 2 is produced.
  
 
|-
 
|-
| 2:40
+
| 02:40
| Pause the video and do this exercise and then resume the video.
+
| Pause the video here and do this exercise and then resume the video.
  
 
|-
 
|-
| 2:45
+
| 02:45
 
|Plot sin(x) in blue color along with linewidth as 3.
 
|Plot sin(x) in blue color along with linewidth as 3.
  
 
|-
 
|-
| 2:53
+
| 02:53
| So, now switch to terminal for solution A combination of color and linewidth would do the job for us.
+
| So, now switch to '''terminal''' for solution. A combination of color and line width would do the job for us.
  
 
|-
 
|-
| 3:01
+
| 03:01
|So , type clf , then type plot within brackets x, sin(x),within single quotes b,linewidth is equal to 3.
+
|So, type '''clf''' , then type '''plot x, sin(x)''', within single quotes '''b''', '''linewidth is equal to 3'''.
  
 
|-
 
|-
| 3:16
+
| 03:16
 
| To get the style of line as bunch of points not joined, pass the linestyle argument with or without color argument.
 
| To get the style of line as bunch of points not joined, pass the linestyle argument with or without color argument.
  
 
|-
 
|-
| 3:25
+
| 03:25
| So for that type on the terminal clf, then type plot x,sin(x),within single quotes dot.
+
| So, for that, type on the terminal '''clf''', then type: '''plot x, sin(x), dot''' in single quotes.
  
 
|-
 
|-
| 3:43
+
| 03:43
 
| We get a plot with only points.
 
| We get a plot with only points.
  
 
|-
 
|-
| 3:49
+
| 03:49
| To get the same plot in blue color type clf, then type plot within brackets x, sin(x),within single quotes b dot.
+
| To get the same plot in blue color, type: '''clf''', then type '''plot x, sin(x),'''within single quotes '''b dot'''.
  
 
|-
 
|-
| 4:02
+
| 04:02
| Other available options for passing arguments can be seen in the documentation of plot.
+
| Other available options for passing arguments can be seen in the documentation of '''plot'''.
  
 
|-
 
|-
| 4:07
+
| 04:07
|For that , you can type in the terminal plot then question mark.
+
|To see that, we can type in the terminal- '''plot''' then question mark.
  
 
|-
 
|-
| 4:19
+
| 04:19
 
| So, you can actually go through the documentation.
 
| So, you can actually go through the documentation.
 
  
 
|-
 
|-
| 4:23
+
| 04:23
| So , you pause the video and do this exercise and then resume the video.
+
| So, pause the video here and do this exercise and then resume the video.
  
 
|-
 
|-
| 4:28
+
| 04:28
|Plot the sine curve with green filled circles.
+
|Plot the '''sine curve''' with green filled circles.
  
 
|-
 
|-
| 4:33
+
| 04:33
| so ,for solutionNow, switch to terminal . We use a combination of linestyle and color.
+
| So, for solution, now switch to the terminal. We use the combination of '''linestyle''' and color.
  
 
|-
 
|-
|4:40
+
|04:40
|So ,type clf() then type plot within brackets x,cos(x), within single quotes go.
+
|So, type '''clf()''' then type '''plot''' within brackets '''x, cos(x)''', within single quotes '''go'''.
  
 
|-
 
|-
|4:56
+
|04:56
|So, Pause the video here, try out the following exercise and resume the video.
+
|So, pause the video here. Try out the following exercise and resume the video.
  
 
|-
 
|-
|5:02
+
|05:02
|Plot the curve of x versus tan(x) in red dash line and linewidth 3.
+
|Plot the curve of 'x' versus 'tan(x)', in red dash line and linewidth 3.
  
 
|-
 
|-
| 5:13
+
| 05:13
| So for solution, we will switch to terminal .  
+
| So, for solution, we will switch to terminal.  
  
 
|-
 
|-
| 5:18
+
| 05:18
|Here we shall use a combination of linewidth argument and linestyle.
+
|Here, we shall use a combination of '''linewidth''' argument and '''linestyle'''.
  
 
|-
 
|-
|5:22
+
|05:22
|So in terminal you can type clf() then plot within brackets x, cos(x), within single quotes r hyphen hyphen
+
|So, in terminal, you can type '''clf()''' then '''plot''' within brackets '''x, cos(x),''' within single quotes '''r''' hyphen hyphen.
  
 
|-
 
|-
| 5:36
+
| 05:36
 
| Now that we know how to produce a bare minimum plot with color, style and thickness of our interest, we shall look at further decorating the plot.
 
| Now that we know how to produce a bare minimum plot with color, style and thickness of our interest, we shall look at further decorating the plot.
  
 
|-
 
|-
5:46
+
05:46
| Let us start with a plot for the function minus x squared plus 4x minus 5.
+
| Let us start with a plot for the '''function''' '''minus x squared plus 4x minus 5'''.
  
 
|-
 
|-
|5:52
+
|05:52
|So for that you have to type clf then plot within brackets x,minus x star x plus 4 star x minus 5,'r',linewidth is equal to 2.
+
|So, for that, you have to type: first '''clf''' then '''plot''' within brackets '''x, minus x star x plus 4 star x minus 5, 'r', linewidth is equal to 2'''.
  
 
|-
 
|-
| 6:16
+
| 06:16
 
| As you can see, the figure does not have any description describing the plot.
 
| As you can see, the figure does not have any description describing the plot.
  
 
|-
 
|-
| 6:21
+
| 06:21
|To add a title to the plot to describe what the plot is,use the <tt>title</tt> command.
+
|To add a '''title''' to the plot to describe what the plot is, use the '''title''' command.
  
 
|-
 
|-
|6:26
+
|06:26
|So, we can type in the terminal title within brackets and double quotes Parabolic function - x squared plus 4x minus 5
+
|So, we can type in the terminal, '''title''' within brackets and double quotes '''Parabolic function - x squared plus 4x minus 5'''
  
 
|-
 
|-
|6:42
+
|06:42
|The figure now has a title.
+
|The figure now has a '''title'''.
  
 
|-
 
|-
|6:45
+
|06:45
| But it is not formatted and does not look clean.
+
| But, it is not formatted and does not look clean.
  
 
|-
 
|-
| 6:49
+
| 06:49
| It would look shabby if there were fractions and more complex functions like log and exp.
+
| It would look shabby if there were '''fraction'''s and more '''complex function'''s like '''log''' and '''exp'''.
  
 
|-
 
|-
| 6:57
+
| 06:57
| So, Wouldn't it be good if the title is seen in LaTeX like formatting?
+
| So, Wouldn't it be good if the title is seen in '''LaTeX''' like formatting?
  
 
|-
 
|-
| 7:03
+
| 07:03
| This is possible by adding a <tt>$</tt> sign before and after the part of the string that should be in LaTeX style.
+
| This is possible by adding a '$' sign before and after the part of the '''string''' that should be in '''LaTeX style'''.
  
 
|-
 
|-
|7:10
+
|07:10
| So in the command you can type title within brackets and double quotes Parabolic function dollar sign minus x squared plus 4x minus 5 dollar sign
+
| So, in the command you can type: '''title''' within brackets '''Parabolic function dollar sign minus x squared plus 4x minus 5 dollar sign'''.
 
+
  
 
|-
 
|-
| 7:26
+
| 07:26
 
| As we can see, the polynomial is now formatted.
 
| As we can see, the polynomial is now formatted.
  
 
|-
 
|-
| 7:30
+
| 07:30
| Pause the video here, try out the following exercise and resume the video.
+
|So, pause the video here. Try out the following exercise and resume the video.
  
 
|-
 
|-
| 7:35
+
| 07:35
| Change the title of the figure such that the whole title is formatted in LaTeX style.
+
| Change the '''title''' of the figure such that the whole title is formatted in '''LaTeX style'''.
  
 
|-
 
|-
| 7:41
+
| 07:41
| Switch to terminal for solution.  
+
|So, for that, switch to terminal for solution.  
  
 
|-
 
|-
| 7:45
+
| 07:45
| The solution is to enclose the whole string in between $.
+
| The solution is to enclose the whole '''string''' in between '$'.
  
 
|-
 
|-
|7:51
+
|07:51
|So you can type title within brackets dollar sign Parabolic function -x squared plus 4x minus 5 dollar sign.
+
|So, you can type: '''title''' within brackets '''dollar sign Parabolic function -x squared plus 4x minus 5 dollar sign'''.
  
 
|-
 
|-
| 8:01
+
| 08:01
| Although we have title, the plot is not complete without labelling x and y axes.  
+
| Although we have title, the plot is not complete without labeling x and y axes.  
  
 
|-
 
|-
| 8:05
+
| 08:05
 
| we shall label x-axis to "x" and y-axis to "f(x)".
 
| we shall label x-axis to "x" and y-axis to "f(x)".
  
 
|-
 
|-
| 8:12
+
| 08:12
|So for that you can type in terminal xlabel within brackets in double quotes x , then in terminal ylabel within brackets in double quotes f of x.
+
|So, for that, you can type in terminal: '''xlabel''' within brackets in double quotes '''x ,''' and then '''ylabel''' in terminal within brackets in double quotes '''f of x'''.
  
 
|-
 
|-
| 8:31
+
| 08:31
| As you can see, <tt>xlabel</tt> and 'ylabel' command takes a string as an argument.  
+
| As you can see, '''xlabel''' and '''ylabel''' commandd take a string as an argument.  
  
 
|-
 
|-
| 8:37
+
| 08:37
| xlabel sets the label to x-axis as 'x' and ylabel sets the name to the y-axis as 'f(x)'.
+
| '''xlabel''' sets the label to x-axis as 'x' and '''ylabel''' sets the name to the y-axis as 'f(x)'.
 
+
  
 
|-
 
|-
| 8:50
+
| 08:50
| Pause the video here, try out the following exercise and resume the video.
+
|So, now pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
| 8:57
+
| 08:57
| Set the x and y labels as "x" and "f(x)" in LaTeX style.
+
| Set the x and y labels as "x" and "f(x)" in '''LaTeX style'''.
  
 
|-
 
|-
| 9:04
+
| 09:04
| Since we need LaTeX style formatting, all we have to do is enclose the string in between two $.
+
| Since we need LaTeX style formatting, all we have to do is enclose the '''string''' in between two dollar symbols ($).
  
 
|-
 
|-
| 9:10
+
| 09:10
| Switch to terminal for solution and type xlabel within brackets dollar sign x dollar sign.
+
| So now, switch to terminal and type: '''xlabel''' within brackets in double quotes in between two dollar signs '''x''' and then type '''ylabel''' and again brackets double quotes in between two dollar signs '''f of x'''.
ylabel within brackets and double quotes dollar sign f of x dollar sign.
+
 
   
 
   
 
 
|-
 
|-
| 9:31
+
| 09:31
 
| The plot is now almost complete except that the points are not named.
 
| The plot is now almost complete except that the points are not named.
  
 
|-
 
|-
| 9:37
+
| 09:37
| For example the point (2, -1) is the local maxima.
+
| For example, the point (2, -1) is the '''local maxima'''.
  
 
|-
 
|-
| 9:42
+
| 09:42
 
| We would like to name the point accordingly.  
 
| We would like to name the point accordingly.  
  
 
|-
 
|-
|9:47
+
|09:47
|To do this use the function <tt>annotate</tt>.
+
|To do this, use the function '''annotate()'''.
  
 
|-
 
|-
|9:49
+
|09:49
|So for that you can type in the terminal annotate within brackets in double quotes local maxima comma xy is equal to within brackets 2 comma -1.
+
|So, for that, you can type in the terminal: '''annotate''' within brackets in double quotes '''local maxima comma xy is equal to''' within brackets '''2 comma -1'''.
  
 
|-
 
|-
 
| 10:04
 
| 10:04
| As you can see, the first argument to <tt>annotate</tt> command is the name we would like to mark the point as, and the second argument is the co-ordinates of the point at which the name should appear.
+
| As you can see, the first argument to '''annotate''' command is the name we would like to mark the point as. And, the second argument is the co-ordinates of the point at which the name should appear.
  
 
|-
 
|-
 
| 10:18
 
| 10:18
| It is a tuple containing two numbers.
+
| It is a '''tuple''' containing two numbers.
  
 
|-
 
|-
Line 310: Line 302:
 
|-
 
|-
 
|10:30
 
|10:30
|Make an annotation called "root" at the point (-4, 0).
+
|Make an '''annotation''' called "root", at the point (-4, 0).
  
 
|-
 
|-
 
| 10:38
 
| 10:38
| What happens to the first annotation ?
+
| What happens to the first annotation?
  
 
|-
 
|-
 
| 10:43
 
| 10:43
| Switch to the terminal for the solution.  
+
| For that, switch to the '''terminal''' for the solution.  
  
 
|-
 
|-
 
|10:46
 
|10:46
|As we can see, every annotate command makes a new annotation on the figure.
+
|As we can see, every '''annotate''' command makes a new annotation on the figure.
  
 
|-
 
|-
 
|10:52
 
|10:52
|Now we have everything we need to decorate a plot, but the plot would be incomplete if we can not set the limits of axes.  
+
|Now, we have everything we need to decorate a plot but the plot would be incomplete if we can not set the limits of axes.  
  
 
|-
 
|-
Line 334: Line 326:
 
|-
 
|-
 
|11:06
 
|11:06
|Else limits also can be get and set from the terminal.
+
|Else, limits also can be get and set from the terminal.
  
 
|-
 
|-
 
| 11:13
 
| 11:13
| Use "xlim()" and "ylim()" functions to get the limits.
+
| Use "xlim()" function  and "ylim()" function to get the '''limit'''s.
  
 
|-
 
|-
 
|11:17
 
|11:17
|So type in the terminal annotate within brackets in double quotes root comma xy is equal to within brackets minus 4 comma 0.
+
|So, type in the terminal: '''annotate''' within brackets in double quotes '''root''' comma '''xy is equal to''' within brackets '''minus 4 comma 0'''.
  
 
|-
 
|-
 
| 11:32
 
| 11:32
| <tt>xlim</tt> function returns the current x axis limits and <tt>ylim</tt> function returns the current y-axis limits.
+
| '''xlim()''' function returns the current x-axis limits and '''ylim()''' function returns the current y-axis limits.
  
 
|-
 
|-
 
|11:41
 
|11:41
|Set the limits of x-axis from -4 to 5 by giving command xlim(-4,5).
+
|Set the '''limit'''s of x-axis from -4 to 5 by giving command '''xlim(-4,5)'''. So, in the terminal, you can type: '''xlim()''' and then again '''ylim ()''' then type '''xlim(-4,5)'''.
  
 
|-
 
|-
 
|  12:12
 
|  12:12
| Similarly set the limits of y-axis appropriately.
+
| Similarly set the limits of y-axis appropriately. So you can type: '''ylim(-15,2)'''.
  
 
|-
 
|-
Line 362: Line 354:
 
|-
 
|-
 
|12:27
 
|12:27
|Set the limits of axes such that the area of interest is the rectangle (-1, -15) and (3, 0)
+
|Set the limits of axes such that the area of interest is the rectangle (-1, -15) and (3, 0).
  
 
|-
 
|-
 
| 12:37
 
| 12:37
| Switch to the terminal for the solution.  
+
| Switch to the '''terminal''' for the solution.  
 
+
  
 
|-
 
|-
Line 379: Line 370:
 
|-
 
|-
 
|12:51
 
|12:51
|So in the command we can type xlim within brackets -1 comma 3 and ylim within brackets -15 comma 0.
+
|So, in the command we can type: '''xlim''' within brackets '''-1 comma 3''' and '''ylim''' within brackets '''-15 comma 0'''.
  
 
|-
 
|-
Line 387: Line 378:
 
|-
 
|-
 
| 13:09
 
| 13:09
| This brings us to the end of this tutorial.In this tutorial,we have learnt to,Modify the attributes of plot like color, line width, line style by passing additional arguments.
+
| This brings us to the end of this tutorial. In this tutorial, we have learnt to: Modify the attributes of '''plot''' like '''color, line width, line style''' by passing additional '''argument'''s.
  
 
|-
 
|-
 
| 13:20
 
| 13:20
|  Add title to a plot using 'title' command.
+
|  Add '''title''' to a plot using 'title' command.
  
 
|-
 
|-
 
| 13:24
 
| 13:24
|  Incorporate LaTeX style formatting by adding a <tt>$</tt> sign before and after the part of the string.
+
|  Incorporate '''LaTeX''' style formatting by adding a '$' sign before and after the part of the '''string'''.
  
 
|-
 
|-
 
| 13:30
 
| 13:30
|  Label x and y axes using xlabel() and ylabel() commands.
+
'''Label''' x and y axes using '''xlabel()''' function and '''ylabel()''' commands.
  
 
|-
 
|-
 
| 13:36
 
| 13:36
| Then, add annotations to a plot using annotate() command.
+
| Then, add annotations to a plot using '''annotate()''' command.
  
 
|-
 
|-
 
| 13:38
 
| 13:38
| Get and set the limits of axes using xlim() and ylim() commands.
+
| Get and set the limits of axes using '''xlim()''' and '''ylim()''' commands.
  
 
|-
 
|-
Line 415: Line 406:
 
|-
 
|-
 
| 13:50
 
| 13:50
| 1. Draw a plot of cosine graph between -2pi to 2pi with line thickness 4.
+
| 1. Draw a '''plot''' of '''cosine graph''' between '-2pi' to '2pi' with line thickness 4.
  
 
|-
 
|-
 
| 13:57
 
| 13:57
| 2. Read through the documentation and find out, is there a way to modify the alignment of text in the command <tt>ylabel</tt>.
+
| 2. Read through the documentation and find out, is there a way to modify the alignment of text in the command '''ylabel'''.
  
 
|-
 
|-
 
| 14:05
 
| 14:05
| Yes or No are the options.
+
| '''Yes''' or '''No''' are the options.
  
 
|-
 
|-
 
| 14:07
 
| 14:07
| And the final question. How do you set the title as x^2-5x+6 in LaTex style formatting.
+
| And the final question. How do you set the '''title''' as 'x^2-5x+6' in '''LaTex''' style formatting.
 
+
  
 
|-
 
|-
 
| 14:15
 
| 14:15
| Now, the answers,
+
| Now, the answers:
  
 
|-
 
|-
 
| 14:20
 
| 14:20
| 1. In order to plot a cosine graph between the points -2pi and 2pi with line thickness 3,we use the <tt>linspace</tt> and <tt>plot</tt> command as, x = linspace(-2*pi, 2*pi)
+
| 1. In order to plot a '''cosine graph''' between the points '-2pi' and '2pi' with line thickness 4, we use the '''linspace''' and '''plot''' command as- '''x = linspace(-2*pi, 2*pi)'''.
  
 
|-
 
|-
 
| 14:41
 
| 14:41
| then plot(x, cos(x), linewidth=4)
+
| then '''plot(x, cos(x), linewidth=4)'''
  
 
|-
 
|-
 
| 14:46
 
| 14:46
| And the second answer is No. We do not have an option to modify the alignment of text in the command <tt>ylabel</tt>.
+
| And the second answer is '''No'''. We do not have an option to modify the alignment of text in the command '''ylabel'''.
  
 
|-
 
|-
 
|14:53
 
|14:53
| Then the third and final one. To set the title in LaTex style formatting,we write the equation between two dollar signs as,
+
| Then the third and final one. To set the title in '''LaTex''' style formatting, we write the equation between two dollar signs as,
 
+
'''title("$x^2-5x+6$")'''.
title("$x^2-5x+6$")
+
  
 
|-
 
|-
 
| 15:11
 
| 15:11
 
| Hope you have enjoyed this tutorial and found it useful.  
 
| Hope you have enjoyed this tutorial and found it useful.  
 
 
  
 
|}
 
|}

Latest revision as of 18:00, 20 February 2017

Time Narration
00:00 Hello friends. Welcome to the tutorial on Embellishing a Plot.
00:06 At the end of this tutorial, you will be able to-

Modify the attributes of the plot -- color, line style, line width. Add a title to the plot with embedded LaTeX. Label X and Y axes. Add annotations to the plot. Set and Get the limits of axes.

00:27 So, before beginning this tutorial, we would suggest you to complete the tutorial on Using plot interactively.
00:34 So, let us start ipython with pylab loaded. Open the terminal and type: ipython hyphen pylab.
00:48 We shall first make a simple plot and start decorating it.
00:54 So, type: x is equal to linspace within brackets -2, 4, 20.
01:06 Then type plot(x, sin(x)).
01:15 As we can see, the default colour and the default thickness of the line is as decided by pylab.
01:23 Wouldn't it be nice if we could control these parameters in the plot?
01:28 This is possible by passing additional arguments to the plot command.
01:33 We shall first clear the figure and plot the same by passing the additional color argument.
01:39 Pass the argument 'r' for red color.
01:44 So, type clf, then plot within brackets x, sin(x), within single quotes r.
02:13 The same plot is seen in red color.
02:16 The thickness of the line can be altered by 'linewidth' argument.
02:20 So, type: plot within brackets x, cos(x), linewidth is equal to 2.
02:34 Now, a plot with line thickness 2 is produced.
02:40 Pause the video here and do this exercise and then resume the video.
02:45 Plot sin(x) in blue color along with linewidth as 3.
02:53 So, now switch to terminal for solution. A combination of color and line width would do the job for us.
03:01 So, type clf , then type plot x, sin(x), within single quotes b, linewidth is equal to 3.
03:16 To get the style of line as bunch of points not joined, pass the linestyle argument with or without color argument.
03:25 So, for that, type on the terminal clf, then type: plot x, sin(x), dot in single quotes.
03:43 We get a plot with only points.
03:49 To get the same plot in blue color, type: clf, then type plot x, sin(x),within single quotes b dot.
04:02 Other available options for passing arguments can be seen in the documentation of plot.
04:07 To see that, we can type in the terminal- plot then question mark.
04:19 So, you can actually go through the documentation.
04:23 So, pause the video here and do this exercise and then resume the video.
04:28 Plot the sine curve with green filled circles.
04:33 So, for solution, now switch to the terminal. We use the combination of linestyle and color.
04:40 So, type clf() then type plot within brackets x, cos(x), within single quotes go.
04:56 So, pause the video here. Try out the following exercise and resume the video.
05:02 Plot the curve of 'x' versus 'tan(x)', in red dash line and linewidth 3.
05:13 So, for solution, we will switch to terminal.
05:18 Here, we shall use a combination of linewidth argument and linestyle.
05:22 So, in terminal, you can type clf() then plot within brackets x, cos(x), within single quotes r hyphen hyphen.
05:36 Now that we know how to produce a bare minimum plot with color, style and thickness of our interest, we shall look at further decorating the plot.
05:46 Let us start with a plot for the function minus x squared plus 4x minus 5.
05:52 So, for that, you have to type: first clf then plot within brackets x, minus x star x plus 4 star x minus 5, 'r', linewidth is equal to 2.
06:16 As you can see, the figure does not have any description describing the plot.
06:21 To add a title to the plot to describe what the plot is, use the title command.
06:26 So, we can type in the terminal, title within brackets and double quotes Parabolic function - x squared plus 4x minus 5
06:42 The figure now has a title.
06:45 But, it is not formatted and does not look clean.
06:49 It would look shabby if there were fractions and more complex functions like log and exp.
06:57 So, Wouldn't it be good if the title is seen in LaTeX like formatting?
07:03 This is possible by adding a '$' sign before and after the part of the string that should be in LaTeX style.
07:10 So, in the command you can type: title within brackets Parabolic function dollar sign minus x squared plus 4x minus 5 dollar sign.
07:26 As we can see, the polynomial is now formatted.
07:30 So, pause the video here. Try out the following exercise and resume the video.
07:35 Change the title of the figure such that the whole title is formatted in LaTeX style.
07:41 So, for that, switch to terminal for solution.
07:45 The solution is to enclose the whole string in between '$'.
07:51 So, you can type: title within brackets dollar sign Parabolic function -x squared plus 4x minus 5 dollar sign.
08:01 Although we have title, the plot is not complete without labeling x and y axes.
08:05 we shall label x-axis to "x" and y-axis to "f(x)".
08:12 So, for that, you can type in terminal: xlabel within brackets in double quotes x , and then ylabel in terminal within brackets in double quotes f of x.
08:31 As you can see, xlabel and ylabel commandd take a string as an argument.
08:37 xlabel sets the label to x-axis as 'x' and ylabel sets the name to the y-axis as 'f(x)'.
08:50 So, now pause the video here, try out the following exercise and resume the video.
08:57 Set the x and y labels as "x" and "f(x)" in LaTeX style.
09:04 Since we need LaTeX style formatting, all we have to do is enclose the string in between two dollar symbols ($).
09:10 So now, switch to terminal and type: xlabel within brackets in double quotes in between two dollar signs x and then type ylabel and again brackets double quotes in between two dollar signs f of x.
09:31 The plot is now almost complete except that the points are not named.
09:37 For example, the point (2, -1) is the local maxima.
09:42 We would like to name the point accordingly.
09:47 To do this, use the function annotate().
09:49 So, for that, you can type in the terminal: annotate within brackets in double quotes local maxima comma xy is equal to within brackets 2 comma -1.
10:04 As you can see, the first argument to annotate command is the name we would like to mark the point as. And, the second argument is the co-ordinates of the point at which the name should appear.
10:18 It is a tuple containing two numbers.
10:20 The first is x co-ordinate and second is y co-ordinate.
10:25 Pause the video, do this exercise and then resume the video.
10:30 Make an annotation called "root", at the point (-4, 0).
10:38 What happens to the first annotation?
10:43 For that, switch to the terminal for the solution.
10:46 As we can see, every annotate command makes a new annotation on the figure.
10:52 Now, we have everything we need to decorate a plot but the plot would be incomplete if we can not set the limits of axes.
11:01 This can be done using the button provided on the plot window.
11:06 Else, limits also can be get and set from the terminal.
11:13 Use "xlim()" function and "ylim()" function to get the limits.
11:17 So, type in the terminal: annotate within brackets in double quotes root comma xy is equal to within brackets minus 4 comma 0.
11:32 xlim() function returns the current x-axis limits and ylim() function returns the current y-axis limits.
11:41 Set the limits of x-axis from -4 to 5 by giving command xlim(-4,5). So, in the terminal, you can type: xlim() and then again ylim () then type xlim(-4,5).
12:12 Similarly set the limits of y-axis appropriately. So you can type: ylim(-15,2).
12:22 Pause the video, do this exercise and then resume the video.
12:27 Set the limits of axes such that the area of interest is the rectangle (-1, -15) and (3, 0).
12:37 Switch to the terminal for the solution.
12:40 As we can see, the lower and upper limits of x-axis in the exercise are -1 and 3 respectively.
12:46 The lower and upper limits of y-axis are -15 and 0 respectively.
12:51 So, in the command we can type: xlim within brackets -1 comma 3 and ylim within brackets -15 comma 0.
13:02 This gives us the required rectangle.
13:09 This brings us to the end of this tutorial. In this tutorial, we have learnt to: Modify the attributes of plot like color, line width, line style by passing additional arguments.
13:20 Add title to a plot using 'title' command.
13:24 Incorporate LaTeX style formatting by adding a '$' sign before and after the part of the string.
13:30 Label x and y axes using xlabel() function and ylabel() commands.
13:36 Then, add annotations to a plot using annotate() command.
13:38 Get and set the limits of axes using xlim() and ylim() commands.
13:46 Here are some self assessment questions for you to solve.
13:50 1. Draw a plot of cosine graph between '-2pi' to '2pi' with line thickness 4.
13:57 2. Read through the documentation and find out, is there a way to modify the alignment of text in the command ylabel.
14:05 Yes or No are the options.
14:07 And the final question. How do you set the title as 'x^2-5x+6' in LaTex style formatting.
14:15 Now, the answers:
14:20 1. In order to plot a cosine graph between the points '-2pi' and '2pi' with line thickness 4, we use the linspace and plot command as- x = linspace(-2*pi, 2*pi).
14:41 then plot(x, cos(x), linewidth=4)
14:46 And the second answer is No. We do not have an option to modify the alignment of text in the command ylabel.
14:53 Then the third and final one. To set the title in LaTex style formatting, we write the equation between two dollar signs as,

title("$x^2-5x+6$").

15:11 Hope you have enjoyed this tutorial and found it useful.

Contributors and Content Editors

Gaurav, Kavita salve, Minal, PoojaMoolya, Sandhya.np14, Sneha