Difference between revisions of "Scilab/C2/Plotting-2D-graphs/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
|||
Line 7: | Line 7: | ||
|- | |- | ||
| 00:00 | | 00:00 | ||
− | | | Welcome to the spoken tutorial on Plotting 2D graphs with | + | | | Welcome to the spoken tutorial on '''Plotting 2D graphs''' with '''Scilab'''. |
|- | |- | ||
| 00:04 | | 00:04 | ||
− | | Assuming that Scilab is installed on your computer, we will discuss plots in Scilab. | + | | Assuming that Scilab is installed on your computer, we will discuss '''plots''' in Scilab. |
|- | |- | ||
Line 19: | Line 19: | ||
|- | |- | ||
|00:15 | |00:15 | ||
− | |The several common charts Scilab can create are: x-y plots, contour plots, 3D plots, histograms, bar charts | + | |The several common charts Scilab can create are: '''x-y plots, contour plots, 3D plots, histograms, bar charts''' etc... |
|- | |- | ||
Line 31: | Line 31: | ||
|- | |- | ||
|00:34 | |00:34 | ||
− | |In order to | + | |In order to plot, we need a set of points. Let us create a sequence of equally spaced points. |
|- | |- | ||
| 00:39 | | 00:39 | ||
− | | This can be done by the linspace command which creates a linearly equally spaced vector. | + | | This can be done by the '''linspace''' command which creates a linearly equally spaced vector. |
|- | |- | ||
| 00:45 | | 00:45 | ||
− | |For Example | + | |For Example, |
|- | |- | ||
Line 45: | Line 45: | ||
|00:48 | |00:48 | ||
− | | x is a row vector with 5 points linearly equally spaced between 1 and 10 | + | | '''x''' is a row vector with 5 points linearly equally spaced between 1 and 10. |
|- | |- | ||
Line 51: | Line 51: | ||
| 00:57 | | 00:57 | ||
− | | Similarly y is a row vector with linearly equally spaced 5 points between 1 and 20 | + | | Similarly '''y''' is a row vector with linearly equally spaced 5 points between 1 and 20. |
|- | |- | ||
Line 57: | Line 57: | ||
|01:08 | |01:08 | ||
− | || More information on linspace | + | || More information on '''linspace''' can be obtained from the '''Help''' documentation. |
|- | |- | ||
Line 63: | Line 63: | ||
|01:14 | |01:14 | ||
− | | | We will now plot a graph with the arguments x and y using the | + | | | We will now plot a graph with the arguments x and y using the '''plot''' function. |
|- | |- | ||
Line 69: | Line 69: | ||
|01:19 | |01:19 | ||
− | || This is similar to the one used in matlab. | + | || This is similar to the one used in '''matlab'''. |
|- | |- | ||
Line 75: | Line 75: | ||
| 01:23 | | 01:23 | ||
− | | | | + | | | '''plot(x,y)''' creates a graph of x verses y as you see. |
|- | |- | ||
Line 81: | Line 81: | ||
|01:31 | |01:31 | ||
− | | | Notice that the | + | | | Notice that the '''Graphics window''' is labeled as '0'. |
|- | |- | ||
Line 87: | Line 87: | ||
| 01:36 | | 01:36 | ||
− | | We will open another graphic window using the xset function. | + | | We will open another graphic window using the '''xset''' function. |
|- | |- | ||
Line 99: | Line 99: | ||
| 01:43 | | 01:43 | ||
− | | Cut the xset function, paste in | + | | Cut the '''xset''' function, paste in Scilab, hit Enter. |
|- | |- | ||
Line 105: | Line 105: | ||
|01:50 | |01:50 | ||
− | | You will see a | + | | You will see a '''Graphic window number 1'''. |
|- | |- | ||
Line 111: | Line 111: | ||
|01:54 | |01:54 | ||
− | | Note that two arguments are passed to this function namely the window and 1. | + | | Note that two arguments are passed to this function namely the 'window' and 1. |
|- | |- | ||
Line 123: | Line 123: | ||
| 02:06 | | 02:06 | ||
− | || For | + | || For Scilab, '''plot2d''' is the native function used to plot 2d graphs. |
|- | |- | ||
Line 129: | Line 129: | ||
| 02:14 | | 02:14 | ||
− | | | plot2d command plots a graph of x verses y as you see. | + | | | '''plot2d''' command plots a graph of x verses y as you see. |
|- | |- | ||
Line 135: | Line 135: | ||
|02:26 | |02:26 | ||
− | || Notice that there is a third argument called style. | + | || Notice that there is a third argument called 'style'. |
|- | |- | ||
Line 141: | Line 141: | ||
| 02:31 | | 02:31 | ||
− | | | | + | | | '''style''' argument is optional. It is used to customize the appearance of the plot. |
|- | |- | ||
Line 147: | Line 147: | ||
|02:36 | |02:36 | ||
− | | | For positive values of style the curve is | + | | | For positive values of style, the curve is plain with different colours like green for 3 in our case. |
|- | |- | ||
Line 165: | Line 165: | ||
|02:51 | |02:51 | ||
− | | | Also we can set the start points and end points for x and y | + | | | Also we can set the start points and end points for x and y axes by passing the fourth argument. |
|- | |- | ||
Line 171: | Line 171: | ||
|02:57 | |02:57 | ||
− | |It is called rect. As you see, | + | |It is called '''rect'''. As you see, |
|- | |- | ||
Line 177: | Line 177: | ||
| 03:07 | | 03:07 | ||
− | || | + | || we have x axis starting from 1 to 10 and y axis from 1 to 20. |
|- | |- | ||
Line 183: | Line 183: | ||
| 03:14 | | 03:14 | ||
− | | The order of argument in the rect command is xmin, ymin, xmax and ymax. | + | | The order of argument in the '''rect''' command is xmin, ymin, xmax and ymax. |
|- | |- | ||
Line 189: | Line 189: | ||
| 03:24 | | 03:24 | ||
− | || Let us now learn about | + | || Let us now learn about title, axis and legends. |
|- | |- | ||
Line 195: | Line 195: | ||
|03:28 | |03:28 | ||
− | || To configure labels to the axis and title to the plot we can use the commands title, | + | || To configure labels to the axis and title to the plot we can use the commands '''title, xlabel''' and '''ylabel'''. |
|- | |- | ||
Line 201: | Line 201: | ||
| 03:38 | | 03:38 | ||
− | || I will cut this set of commands and paste in the console. Hit | + | || I will cut this set of commands and paste in the console. Hit Enter. |
|- | |- | ||
Line 207: | Line 207: | ||
| 03:45 | | 03:45 | ||
− | | | You will see that the graph has been labeled x to the x axis, y to the y axis and the title of the graph is | + | | | You will see that the graph has been labeled x to the x-axis, y to the y-axis and the title of the graph is 'My title'. |
|- | |- | ||
Line 213: | Line 213: | ||
|03:58 | |03:58 | ||
− | | | You may want to configure the title and | + | | | You may want to configure the '''title''' and '''axes''' of the plot in a single command instead of 3 |
|- | |- | ||
| 04:04 | | 04:04 | ||
− | | |For this purpose we use the xtitle command with all the 3 arguments. | + | | |For this purpose we use the '''xtitle''' command with all the 3 arguments. |
|- | |- | ||
Line 224: | Line 224: | ||
| 04:11 | | 04:11 | ||
− | | | I will cut this command paste in scilab | + | | | I will cut this command, paste in scilab, '''Enter'''. |
|- | |- | ||
Line 230: | Line 230: | ||
|04:18 | |04:18 | ||
− | | | Now you see that the x axis label is X axis , Y axis and the title is My title. | + | | | Now you see that the x axis label is X axis , Y axis and the title is 'My title'. |
|- | |- | ||
Line 236: | Line 236: | ||
|04:26 | |04:26 | ||
− | | | The clf() function that | + | | | The '''clf()''' function that I am typing now, will clear the graphic window as you see. |
|- | |- | ||
Line 242: | Line 242: | ||
| 04:36 | | 04:36 | ||
− | | | It is useful while plotting different | + | | | It is useful while plotting different graphs on the same graphic window. |
|- | |- | ||
Line 260: | Line 260: | ||
| 04:51 | | 04:51 | ||
− | | | Let us see an example for this I will scroll down | + | | | Let us see an example for this, I will scroll down. |
|- | |- | ||
Line 266: | Line 266: | ||
|04:56 | |04:56 | ||
− | || We will define the x axis points in a row vector x using the linspace command | + | || We will define the x-axis points in a row vector '''x''' using the '''linspace''' command. |
|- | |- | ||
Line 272: | Line 272: | ||
|05:03 | |05:03 | ||
− | || Let us define a function | + | || Let us define a function |
|- | |- | ||
Line 278: | Line 278: | ||
| 05:05 | | 05:05 | ||
− | | |y1 = x square | + | | |y1 = x square. |
|- | |- | ||
Line 284: | Line 284: | ||
| 05:07 | | 05:07 | ||
− | | |plot x verses y1 | + | | |plot x verses y1. |
|- | |- | ||
Line 290: | Line 290: | ||
|05:10 | |05:10 | ||
− | | | | + | | | Define another function y2 = 2 x square. |
|- | |- | ||
|05:15 | |05:15 | ||
− | | |plot x verses y2 | + | | |plot x verses y2. |
|- | |- | ||
Line 300: | Line 300: | ||
| 05:17 | | 05:17 | ||
− | | | We will also give label and title to our graph | + | | | We will also give label and title to our graph. |
|- | |- | ||
Line 306: | Line 306: | ||
|05:22 | |05:22 | ||
− | || Notice that we have additionally passed ”o-” and ”+ -” commands to the plot function, to change the appearance of the curve | + | || Notice that we have additionally passed ”o-” and ”+ -” commands to the plot function, to change the appearance of the curve. |
|- | |- | ||
Line 312: | Line 312: | ||
|05:33 | |05:33 | ||
− | | | + | | | These arguments are not a part of the '''plot2d''' function. |
|- | |- | ||
Line 318: | Line 318: | ||
| 05:37 | | 05:37 | ||
− | | | They can be used only with the plot function | + | | | They can be used only with the '''plot''' function. |
|- | |- | ||
Line 324: | Line 324: | ||
| 05:41 | | 05:41 | ||
− | | | I will copy these set of commands and paste in the | + | | | I will copy these set of commands and paste in the Scilab console. |
|- | |- | ||
Line 330: | Line 330: | ||
| 05:49 | | 05:49 | ||
− | | | You see the graph | + | | | You see the graph. |
|- | |- | ||
Line 342: | Line 342: | ||
| 05:56 | | 05:56 | ||
− | || This can be achieved using the legend command | + | || This can be achieved using the '''legend''' command as you see. |
|- | |- | ||
Line 348: | Line 348: | ||
| 06:08 | | 06:08 | ||
− | || "o-" curve represents function y1=x square and "+-" curve represents function y2=2*x^2 | + | || "o-" curve represents function y1=x square and "+-" curve represents function y2=2*x^2 (y2=2x square) |
|- | |- | ||
Line 354: | Line 354: | ||
| 06:19 | | 06:19 | ||
− | || I will close this graphic window | + | || I will close this graphic window. |
|- | |- | ||
Line 360: | Line 360: | ||
| 06:22 | | 06:22 | ||
− | | | We will now discuss about plot2d demos and subplot function | + | | | We will now discuss about '''plot2d demos''' and '''subplot''' function. |
|- | |- | ||
Line 366: | Line 366: | ||
| 06:28 | | 06:28 | ||
− | | | Scilab provides demos for all its major functions. | + | | | Scilab provides '''demos''' for all its major functions. |
|- | |- | ||
Line 372: | Line 372: | ||
| 06:31 | | 06:31 | ||
− | | Demos of plot2d can be viewed through the demonstration tab. | + | | '''Demos''' of '''plot2d''' can be viewed through the '''demonstration''' tab. |
|- | |- | ||
Line 378: | Line 378: | ||
|06:39 | |06:39 | ||
− | | | Click on Graphics, click | + | | | Click on '''Graphics''', click '''2D and 3D plots''' and select a demo out of the various demos provided. |
|- | |- | ||
Line 384: | Line 384: | ||
|06:51 | |06:51 | ||
− | | I will click on plot2d. | + | | I will click on '''plot2d'''. |
|- | |- | ||
Line 390: | Line 390: | ||
| 06:54 | | 06:54 | ||
− | | | You will see the demo graph | + | | | You will see the demo graph. |
|- | |- | ||
Line 396: | Line 396: | ||
|06:55 | |06:55 | ||
− | || The code for this graph can also be seen by clicking on the view code button here. | + | || The code for this graph can also be seen by clicking on the '''view code''' button here. |
|- | |- | ||
Line 402: | Line 402: | ||
| 07:02 | | 07:02 | ||
− | | | This link does not open in Mac OS but it works in | + | | | This link does not open in '''Mac OS''' but it works in '''Windows''' and '''Linux'''. |
|- | |- | ||
Line 420: | Line 420: | ||
|07:15 | |07:15 | ||
− | | | Currently | + | | | Currently I am in 'demos' directory of Scilab 5.2 as shown. |
|- | |- | ||
Line 432: | Line 432: | ||
|07:27 | |07:27 | ||
− | || We will type ls to see the list of demos available, | + | || We will type '''ls''' to see the list of demos available, as you see here. |
|- | |- | ||
Line 438: | Line 438: | ||
| 07:36 | | 07:36 | ||
− | | Then we will select the 2d_3d_plots directory and hit | + | | Then we will select the 2d_3d_plots directory and hit '''Enter'''. |
|- | |- | ||
Line 444: | Line 444: | ||
| 07:46 | | 07:46 | ||
− | | Type ls again to see the various demo code available in the sce files | + | | Type '''ls''' again to see the various '''demo code''' available in the 'sce' files. |
|- | |- | ||
Line 450: | Line 450: | ||
| 07:55 | | 07:55 | ||
− | | | | + | | | We will view the code for the demo which we have seen earlier. |
|- | |- | ||
Line 456: | Line 456: | ||
| 08:00 | | 08:00 | ||
− | | | Type more plot2d.dem.sce and hit | + | | | Type '''more plot2d.dem.sce''' and hit '''Enter'''. |
|- | |- | ||
Line 462: | Line 462: | ||
|08:11 | |08:11 | ||
− | || Here you will see the code for the demo graph of plot2d function | + | || Here you will see the code for the demo graph of plot2d function. |
|- | |- | ||
Line 474: | Line 474: | ||
| 08:21 | | 08:21 | ||
− | |I will close the demo graph and the demo window | + | |I will close the demo graph and the demo window. |
|- | |- | ||
Line 480: | Line 480: | ||
| 08:26 | | 08:26 | ||
− | | | Similarly you can go through the other demos and explore | + | | | Similarly you can go through the other demos and explore Scilab. |
|- | |- | ||
Line 486: | Line 486: | ||
|08:29 | |08:29 | ||
− | | | Let us now discuss about | + | | | Let us now discuss about '''subplot''' function. |
|- | |- | ||
Line 492: | Line 492: | ||
| 08:33 | | 08:33 | ||
− | || The subplot() function divides the graphics window into a matrix of sub-windows. | + | || The '''subplot()''' function divides the graphics window into a matrix of sub-windows. |
|- | |- | ||
Line 498: | Line 498: | ||
| 08:37 | | 08:37 | ||
− | | | To explain this function we will use demos for plotting 2D graphs in | + | | | To explain this function we will use demos for plotting 2D graphs in Scilab. |
|- | |- | ||
Line 504: | Line 504: | ||
| 08:43 | | 08:43 | ||
− | | |For example, type | + | | |For example, type '''plot2d''' in your console and see the demo plot for this function. |
|- | |- | ||
Line 516: | Line 516: | ||
| 09:00 | | 09:00 | ||
− | | The subplot command breaks the graphics window into a 2 by 2 matrix of sub-windows represented by the first two arguments in the subplot command. | + | | The '''subplot''' command breaks the graphics window into a '2 by 2' matrix of sub-windows represented by the first two arguments in the subplot command. |
|- | |- | ||
Line 522: | Line 522: | ||
| 09:10 | | 09:10 | ||
− | | |The third argument denotes the current window in which the plot will be plotted | + | | |The third argument denotes the current window in which the plot will be plotted. |
|- | |- | ||
Line 528: | Line 528: | ||
| 09:15 | | 09:15 | ||
− | || I will execute this whole set of commands by copying it to the scilab console | + | || I will execute this whole set of commands by copying it to the scilab console. |
|- | |- | ||
Line 540: | Line 540: | ||
| 09:28 | | 09:28 | ||
− | | | The plot obtained can be saved as | + | | | The plot obtained can be saved as an image on your computer. |
|- | |- | ||
Line 546: | Line 546: | ||
| 09:32 | | 09:32 | ||
− | | Click on the graphic window, go to File menu select | + | | Click on the graphic window, go to '''File''' menu, select '''Export to''' . |
|- | |- | ||
Line 552: | Line 552: | ||
| 09:39 | | 09:39 | ||
− | | | Give a suitable title to your plot | + | | | Give a suitable title to your plot. |
|- | |- | ||
Line 570: | Line 570: | ||
| 09:59 | | 09:59 | ||
− | | | I will select the JPEG format and | + | | | I will select the JPEG format and click '''Save'''. |
|- | |- | ||
Line 582: | Line 582: | ||
| 10:11 | | 10:11 | ||
− | | | This brings us to the end of this spoken tutorial on Plotting in Scilab. | + | | | This brings us to the end of this spoken tutorial on '''Plotting in Scilab'''. |
|- | |- | ||
Line 606: | Line 606: | ||
|10:29 | |10:29 | ||
− | | | More information on the same is available on the following link | + | | | More information on the same is available on the following link. |
|- | |- | ||
Line 612: | Line 612: | ||
|10:32 | |10:32 | ||
− | | |Thanks for joining. Good bye | + | | |Thanks for joining. Good bye. |
|} | |} |
Revision as of 11:50, 26 February 2015
Time | Narration |
00:00 | Welcome to the spoken tutorial on Plotting 2D graphs with Scilab. |
00:04 | Assuming that Scilab is installed on your computer, we will discuss plots in Scilab. |
00:10 | Scilab offers many ways to create and customize various types of 2D and 3D plots. |
00:15 | The several common charts Scilab can create are: x-y plots, contour plots, 3D plots, histograms, bar charts etc... |
00:24 | Now open your Scilab console window. |
00:28 | I will use Plotting.sce file to cut and paste the commands. |
00:34 | In order to plot, we need a set of points. Let us create a sequence of equally spaced points. |
00:39 | This can be done by the linspace command which creates a linearly equally spaced vector. |
00:45 | For Example, |
00:48 | x is a row vector with 5 points linearly equally spaced between 1 and 10. |
00:57 | Similarly y is a row vector with linearly equally spaced 5 points between 1 and 20. |
01:08 | More information on linspace can be obtained from the Help documentation. |
01:14 | We will now plot a graph with the arguments x and y using the plot function. |
01:19 | This is similar to the one used in matlab. |
01:23 | plot(x,y) creates a graph of x verses y as you see. |
01:31 | Notice that the Graphics window is labeled as '0'. |
01:36 | We will open another graphic window using the xset function. |
01:41 | I will close this. |
01:43 | Cut the xset function, paste in Scilab, hit Enter. |
01:50 | You will see a Graphic window number 1. |
01:54 | Note that two arguments are passed to this function namely the 'window' and 1. |
02:03 | The next graph will be plotted on this window. |
02:06 | For Scilab, plot2d is the native function used to plot 2d graphs. |
02:14 | plot2d command plots a graph of x verses y as you see. |
02:26 | Notice that there is a third argument called 'style'. |
02:31 | style argument is optional. It is used to customize the appearance of the plot. |
02:36 | For positive values of style, the curve is plain with different colours like green for 3 in our case. |
02:44 | The default value of style is 1. |
02:46 | Try plotting graphs for negative values and see the difference in appearance yourself. |
02:51 | Also we can set the start points and end points for x and y axes by passing the fourth argument. |
02:57 | It is called rect. As you see, |
03:07 | we have x axis starting from 1 to 10 and y axis from 1 to 20. |
03:14 | The order of argument in the rect command is xmin, ymin, xmax and ymax. |
03:24 | Let us now learn about title, axis and legends. |
03:28 | To configure labels to the axis and title to the plot we can use the commands title, xlabel and ylabel. |
03:38 | I will cut this set of commands and paste in the console. Hit Enter. |
03:45 | You will see that the graph has been labeled x to the x-axis, y to the y-axis and the title of the graph is 'My title'. |
03:58 | You may want to configure the title and axes of the plot in a single command instead of 3 |
04:04 | For this purpose we use the xtitle command with all the 3 arguments. |
04:11 | I will cut this command, paste in scilab, Enter. |
04:18 | Now you see that the x axis label is X axis , Y axis and the title is 'My title'. |
04:26 | The clf() function that I am typing now, will clear the graphic window as you see. |
04:36 | It is useful while plotting different graphs on the same graphic window. |
04:41 | I will close this window. |
04:44 | Sometimes we need to compare two sets of data in the same plot, that is, one set of x data and two sets of y data. |
04:51 | Let us see an example for this, I will scroll down. |
04:56 | We will define the x-axis points in a row vector x using the linspace command. |
05:03 | Let us define a function |
05:05 | y1 = x square. |
05:07 | plot x verses y1. |
05:10 | Define another function y2 = 2 x square. |
05:15 | plot x verses y2. |
05:17 | We will also give label and title to our graph. |
05:22 | Notice that we have additionally passed ”o-” and ”+ -” commands to the plot function, to change the appearance of the curve. |
05:33 | These arguments are not a part of the plot2d function. |
05:37 | They can be used only with the plot function. |
05:41 | I will copy these set of commands and paste in the Scilab console. |
05:49 | You see the graph. |
05:51 | Wouldn't it be of great help to know which curve is associated with which function? |
05:56 | This can be achieved using the legend command as you see. |
06:08 | "o-" curve represents function y1=x square and "+-" curve represents function y2=2*x^2 (y2=2x square) |
06:19 | I will close this graphic window. |
06:22 | We will now discuss about plot2d demos and subplot function. |
06:28 | Scilab provides demos for all its major functions. |
06:31 | Demos of plot2d can be viewed through the demonstration tab. |
06:39 | Click on Graphics, click 2D and 3D plots and select a demo out of the various demos provided. |
06:51 | I will click on plot2d. |
06:54 | You will see the demo graph. |
06:55 | The code for this graph can also be seen by clicking on the view code button here. |
07:02 | This link does not open in Mac OS but it works in Windows and Linux. |
07:07 | Never the less in Mac the code can be viewed through the directory. |
07:12 | Let us go to the terminal. |
07:15 | Currently I am in 'demos' directory of Scilab 5.2 as shown. |
07:21 | The full path to this directory is shown here. |
07:27 | We will type ls to see the list of demos available, as you see here. |
07:36 | Then we will select the 2d_3d_plots directory and hit Enter. |
07:46 | Type ls again to see the various demo code available in the 'sce' files. |
07:55 | We will view the code for the demo which we have seen earlier. |
08:00 | Type more plot2d.dem.sce and hit Enter. |
08:11 | Here you will see the code for the demo graph of plot2d function. |
08:18 | I will close the terminal. |
08:21 | I will close the demo graph and the demo window. |
08:26 | Similarly you can go through the other demos and explore Scilab. |
08:29 | Let us now discuss about subplot function. |
08:33 | The subplot() function divides the graphics window into a matrix of sub-windows. |
08:37 | To explain this function we will use demos for plotting 2D graphs in Scilab. |
08:43 | For example, type plot2d in your console and see the demo plot for this function. |
08:58 | I will close this window. |
09:00 | The subplot command breaks the graphics window into a '2 by 2' matrix of sub-windows represented by the first two arguments in the subplot command. |
09:10 | The third argument denotes the current window in which the plot will be plotted. |
09:15 | I will execute this whole set of commands by copying it to the scilab console. |
09:24 | You can see 4 plots in a single plot window . |
09:28 | The plot obtained can be saved as an image on your computer. |
09:32 | Click on the graphic window, go to File menu, select Export to . |
09:39 | Give a suitable title to your plot. |
09:50 | Select a destination folder to save your file. |
09:54 | Select the file format in which you want your image to appear. |
09:59 | I will select the JPEG format and click Save. |
10:05 | Browse through the directory to open the image and verify yourself whether it has been saved or not. |
10:11 | This brings us to the end of this spoken tutorial on Plotting in Scilab. |
10:15 | There are many other functions in Scilab which will be covered in other spoken tutorials. |
10:20 | Keep watching the Scilab links. |
10:22 | Spoken Tutorials are part of the Talk to a Teacher project, supported by the National Mission on Education through ICT. |
10:29 | More information on the same is available on the following link. |
10:32 | Thanks for joining. Good bye. |