Difference between revisions of "Python/C2/Other-types-of-plots/English-timed"
From Script | Spoken-Tutorial
(Created page with '{| border=1 !Visual Cue !Narration |- | 0:01 | Hello Friends and welcome to the tutorial on <tt>Other types of plots</tt>. |- | 0:06 | Till now we have seen only one kind of plo…') |
|||
Line 4: | Line 4: | ||
|- | |- | ||
| 0:01 | | 0:01 | ||
− | | Hello Friends and welcome to the tutorial on | + | | Hello Friends and welcome to the tutorial on Other types of plots |
|- | |- | ||
Line 42: | Line 42: | ||
|- | |- | ||
| 1:01 | | 1:01 | ||
− | | Before we | + | | Before we proceed further , start your IPython interpreter |
|- | |- | ||
Line 54: | Line 54: | ||
|- | |- | ||
| 1:22 | | 1:22 | ||
− | | The data for the same is available in the file | + | | The data for the same is available in the file company-a-data.txt. |
|- | |- | ||
Line 66: | Line 66: | ||
|- | |- | ||
| 2:02 | | 2:02 | ||
− | | To produce the scatter plot, we first need to load the data from the file using | + | | To produce the scatter plot, we first need to load the data from the file using loadtxt command. |
|- | |- | ||
Line 79: | Line 79: | ||
|- | |- | ||
| 2:57 | | 2:57 | ||
− | | The | + | | The dtype=type within bracket int() argument in loadtxt converts the value to integer, as we require the data as integer further in the tutorial. |
|- | |- | ||
| 3:11 | | 3:11 | ||
− | | Now in-order to generate the scatter graph we will use the function | + | | Now in-order to generate the scatter graph we will use the function scatter() |
− | + | ||
|- | |- | ||
|3:18 | |3:18 | ||
Line 91: | Line 90: | ||
|- | |- | ||
| 3:32 | | 3:32 | ||
− | | Notice that we passed two arguments to | + | | Notice that we passed two arguments to scatter() function, first one the values in x-coordinate, year, and the other the values in y-coordinate, the profit percentage. |
|- | |- | ||
Line 111: | Line 110: | ||
|- | |- | ||
| 4:49 | | 4:49 | ||
− | | Plot a pie chart representing the profit percentage of company A, with the same data from file | + | | Plot a pie chart representing the profit percentage of company A, with the same data from file company-a-data.tx. |
|- | |- | ||
Line 119: | Line 118: | ||
|- | |- | ||
| 5:11 | | 5:11 | ||
− | | We can plot the pie chart using the function | + | | We can plot the pie chart using the function pie() |
|- | |- | ||
|5:15 | |5:15 | ||
− | |Type pie within bracket profit comma labels=year | + | |So Type pie within bracket profit comma labels=year |
|- | |- | ||
| 5:29 | | 5:29 | ||
− | | Notice that we passed two arguments to the function | + | | Notice that we passed two arguments to the function pie(). |
|- | |- | ||
Line 136: | Line 135: | ||
|- | |- | ||
| 5:38 | | 5:38 | ||
− | | Plot a pie chart with the same data with colors for each wedges as white, red, black, magenta,yellow, blue, green, cyan, yellow, magenta and blue respectively. | + | | Plot a pie chart with the same data with red colors for each wedges as white, red, black, magenta,yellow, blue, green, cyan, yellow, magenta and blue respectively. |
|- | |- | ||
Line 152: | Line 151: | ||
|- | |- | ||
| 6:19 | | 6:19 | ||
− | | Plot a bar chart representing the profit percentage of company A, with the same data from file | + | | Plot a bar chart representing the profit percentage of company A, with the same data from file company-a-data.txt. |
|- | |- | ||
Line 160: | Line 159: | ||
|- | |- | ||
| 6:34 | | 6:34 | ||
− | | We can plot the bar chart using the function | + | | We can plot the bar chart using the function bar() and hit enter. |
|- | |- | ||
|6:44 | |6:44 | ||
− | | | + | |So inside that bracket you can put bar , year ,comma profit |
|- | |- | ||
| 6:52 | | 6:52 | ||
− | | Note that the function | + | | Note that the function bar()needs at least two arguments one the values in x-coordinate and the other values in y-coordinate which is used to determine the height of the bars. |
|- | |- | ||
| 7:05 | | 7:05 | ||
− | | Plot a bar chart which is not filled and which is hatched with 45 | + | | Plot a bar chart which is not filled and which is hatched with 45 slanting lines as shown in the image. |
|- | |- | ||
| 7:17 | | 7:17 | ||
− | |The data for the chart may be obtained from the file | + | |The data for the chart may be obtained from the file company-a-data.txt |
|- | |- | ||
|7:26 | |7:26 | ||
− | |Type bar within bracket year comma profit comma fill=False comma hatch= | + | |Type bar within bracket year comma profit comma fill=False comma hatch= within single quote slashhit enter |
|- | |- | ||
Line 192: | Line 191: | ||
|- | |- | ||
| 8:24 | | 8:24 | ||
− | | Because of the nonlinear scaling of the axes, a function of the form y = ax | + | | Because of the nonlinear scaling of the axes, a function of the form y = ax b will appear as a straight line on a log-log graph |
|- | |- | ||
| 8:38 | | 8:38 | ||
− | | Plot a ''log-log'' chart of y=5 into | + | | Plot a ''log-log'' chart of y=5 into x3for x from 1-20. |
|- | |- | ||
Line 205: | Line 204: | ||
|8:54 | |8:54 | ||
|x = linspace within brackets 1 comma 20 comma 100 | |x = linspace within brackets 1 comma 20 comma 100 | ||
− | y = 5 into x | + | y = 5 into x into 3 |
|- | |- | ||
Line 213: | Line 212: | ||
|- | |- | ||
| 9:28 | | 9:28 | ||
− | | Now we can plot the log-log chart using | + | | Now we can plot the log-log chart using loglog()function, |
|- | |- | ||
Line 221: | Line 220: | ||
|- | |- | ||
| 9:48 | | 9:48 | ||
− | | To understand the difference between a normal | + | | To understand the difference between a normal plot and a log-log plot let us create another plot using the function plot. |
|- | |- | ||
|9:57 | |9:57 | ||
− | |figure within brackets 2 | + | |figure within brackets 2 THen type plot within brackets x comma y |
− | plot within brackets x comma y | + | |
|- | |- | ||
| 10:24 | | 10:24 | ||
− | | The difference is clear.So that was | + | | The difference is clear.So that was log-log() plot. |
|- | |- | ||
Line 250: | Line 248: | ||
|- | |- | ||
| 11:20 | | 11:20 | ||
− | | 1. Plot a scatter plot using | + | | 1. Plot a scatter plot using scatter() function |
|- | |- | ||
| 11:22 | | 11:22 | ||
− | | 2. Plot a pie chart using | + | | 2. Plot a pie chart using pie() function |
|- | |- | ||
| 11:25 | | 11:25 | ||
− | | 3. Plot a bar chart using | + | | 3. Plot a bar chart using bar() function |
|- | |- | ||
| 11:28 | | 11:28 | ||
− | | 4. Plot a log-log graph using | + | | 4. Plot a log-log graph using loglog() function |
|- | |- | ||
Line 270: | Line 268: | ||
|- | |- | ||
| 11:42 | | 11:42 | ||
− | | | + | |So there are few some self assessment questions for you to solve. |
|- | |- | ||
| 11:46 | | 11:46 | ||
− | |1. | + | |1. scatter x comma y comma color=blue marker= d and plot x comma y comma color=b comma marker= d) does exactly the same. |
|- | |- | ||
Line 282: | Line 280: | ||
|- | |- | ||
| 12:07 | | 12:07 | ||
− | | . What statement can be issued to generate a bar chart with vertical line hatching. | + | | 2. What statement can be issued to generate a bar chart with vertical line hatching. |
|- | |- | ||
| 12:15 | | 12:15 | ||
− | | bar within | + | | 1.bar within function x comma y comma color=in single quote w comma hatch= slash |
|- | |- | ||
| 12:27 | | 12:27 | ||
− | | bar within bracket x comma y comma fill=False comma hatch=slash slash | + | |2. bar within bracket x comma y comma fill=False comma hatch=slash slash |
|- | |- | ||
| 12:38 | | 12:38 | ||
− | | bar within bracket x comma y comma fill=False comma hatch=in single quote | + | | bar within bracket x comma y comma fill=False comma hatch=in single quote| |
|- | |- | ||
| 12:52 | | 12:52 | ||
− | | bar within bracket x comma y comma color= | + | | bar within bracket x comma y comma color= within quote w comma hatch=single quote |
|- | |- | ||
| 13:02 | | 13:02 | ||
− | | And the answers, | + | | And now the answers, |
|- | |- | ||
Line 314: | Line 312: | ||
|- | |- | ||
| 13:13 | | 13:13 | ||
− | | 2. | + | | 2.bar x comma y comma fill=False comma hatch=bar is the correct option to generate a bar chart with vertical line hatching. |
|- | |- |
Revision as of 12:26, 11 March 2013
Visual Cue | Narration |
---|---|
0:01 | Hello Friends and welcome to the tutorial on Other types of plots |
0:06 | Till now we have seen only one kind of plotting. |
0:10 | Hence in this tutorial we will be looking at some more kinds of plots. |
0:16 | At the end of this tutorial, you will be able to
|
0:29 | So let us begin with scatter plot |
0:33 | Before beginning this tutorial,we would suggest you to complete the tutorial on "Loading data from files" and "Plotting data". |
0:42 | In a scatter plot, the data is displayed as a collection of points, where each point determines it's position on the horizontal axis and the vertical axis respectively. |
0:54 | This kind of plot is also called a scatter chart, a scatter diagram or a scatter graph. |
1:01 | Before we proceed further , start your IPython interpreter |
1:06 | So type ipython hypen pylab |
1:13 | Plot a scatter plot showing the percentage profit of a company A from the year 2000-2010. |
1:22 | The data for the same is available in the file company-a-data.txt. |
1:33 | Type cat space slash home slash fossee bacslash other-plot slash company-a-data.txt (enter) |
1:50 | The data file has two lines with a set of values in each line, the first line representing years and the second line representing the profit percentages. |
2:02 | To produce the scatter plot, we first need to load the data from the file using loadtxt command. |
2:10 | Type year,profit = loadtxt within bracket in single quote slash home slash fossee slash other-plot slash company-a-data.txt comma dtype=type in bracket int() hit enter
|
2:52 | By default loadtxt converts the value to float. |
2:57 | The dtype=type within bracket int() argument in loadtxt converts the value to integer, as we require the data as integer further in the tutorial. |
3:11 | Now in-order to generate the scatter graph we will use the function scatter() |
3:18 | Type scatter within bracket year comma profit and hit enter |
3:32 | Notice that we passed two arguments to scatter() function, first one the values in x-coordinate, year, and the other the values in y-coordinate, the profit percentage. |
3:57 | Plot a scatter plot of the same data in company-a-data.txt with red diamond markers. |
4:09 | Pause the video here, try out the following exercise and resume the video. |
4:17 | Now let us see another kind of plot, the pie chart, for the same data. |
4:40 | A pie chart or a circle graph is a circular chart divided into sectors, illustrating proportion. |
4:49 | Plot a pie chart representing the profit percentage of company A, with the same data from file company-a-data.tx. |
5:00 | So let us reuse the data we have loaded from the file previously. |
5:11 | We can plot the pie chart using the function pie() |
5:15 | So Type pie within bracket profit comma labels=year
|
5:29 | Notice that we passed two arguments to the function pie(). |
5:33 | First one the values and the next one the set of labels to be used in the pie chart. |
5:38 | Plot a pie chart with the same data with red colors for each wedges as white, red, black, magenta,yellow, blue, green, cyan, yellow, magenta and blue respectively. |
5:58 | Pause the video here, try out the following exercise and resume the video. |
6:05 | Now let us move on to the bar charts. |
6:08 | A bar chart or bar graph is a chart with rectangular bars with lengths proportional to the values that they represent. |
6:19 | Plot a bar chart representing the profit percentage of company A, with the same data from file company-a-data.txt. |
6:30 | So let us reuse the data we have loaded from the file previously. |
6:34 | We can plot the bar chart using the function bar() and hit enter. |
6:44 | So inside that bracket you can put bar , year ,comma profit |
6:52 | Note that the function bar()needs at least two arguments one the values in x-coordinate and the other values in y-coordinate which is used to determine the height of the bars. |
7:05 | Plot a bar chart which is not filled and which is hatched with 45 slanting lines as shown in the image. |
7:17 | The data for the chart may be obtained from the file company-a-data.txt |
7:26 | Type bar within bracket year comma profit comma fill=False comma hatch= within single quote slashhit enter |
8:05 | Now let us move on to the log-log plot. |
8:10 | A log-log graph or a log-log plot is a two-dimensional graph of numerical data that uses logarithmic scales on both the horizontal and vertical axes. |
8:24 | Because of the nonlinear scaling of the axes, a function of the form y = ax b will appear as a straight line on a log-log graph |
8:38 | Plot a log-log chart of y=5 into x3for x from 1-20. |
8:49 | Before we actually plot let us calculate the points needed for that. |
8:54 | x = linspace within brackets 1 comma 20 comma 100
y = 5 into x into 3 |
9:23 | Here is the syntax of the log-log function. |
9:28 | Now we can plot the log-log chart using loglog()function, |
9:34 | Type loglog within brackets x comma y hit enter |
9:48 | To understand the difference between a normal plot and a log-log plot let us create another plot using the function plot. |
9:57 | figure within brackets 2 THen type plot within brackets x comma y |
10:24 | The difference is clear.So that was log-log() plot. |
10:33 | Now we will see few more plots and also see how to access help of matplotlib over the Internet. |
10:43 | Help about matplotlib can be obtained from matplotlib.sourceforge.net/contents.html |
10:55 | More plots can be seen at matplotlib.sourceforge.net slash users slash screenshots.html and also at matplotlib.sourceforge.net slash gallery.html |
11:13 | This brings us to the end of this tutorial. In this tutorial we learnt to, |
11:20 | 1. Plot a scatter plot using scatter() function |
11:22 | 2. Plot a pie chart using pie() function |
11:25 | 3. Plot a bar chart using bar() function |
11:28 | 4. Plot a log-log graph using loglog() function |
11:33 | 5. Access the matplotlib online help.Thank you. |
11:42 | So there are few some self assessment questions for you to solve. |
11:46 | 1. scatter x comma y comma color=blue marker= d and plot x comma y comma color=b comma marker= d) does exactly the same. |
12:04 | Is True or False? |
12:07 | 2. What statement can be issued to generate a bar chart with vertical line hatching. |
12:15 | 1.bar within function x comma y comma color=in single quote w comma hatch= slash |
12:27 | 2. bar within bracket x comma y comma fill=False comma hatch=slash slash |
12:38 | |
12:52 | bar within bracket x comma y comma color= within quote w comma hatch=single quote |
13:02 | And now the answers, |
13:06 | 1. False. |
13:9 | Both functions do not produce the same kind of plot. |
13:13 | 2.bar x comma y comma fill=False comma hatch=bar is the correct option to generate a bar chart with vertical line hatching. |
13:31 | Hope you have enjoyed this tutorial and found it useful. |
13:34 | Thank you! |