Difference between revisions of "Python/C2/Other-types-of-plots/English-timed"
From Script | Spoken-Tutorial
Line 65: | Line 65: | ||
|- | |- | ||
− | | | + | |2:02 |
| To produce the scatter plot, we first need to load the data from the file using loadtxt command. | | To produce the scatter plot, we first need to load the data from the file using loadtxt command. | ||
|- | |- | ||
|2:10 | |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 | + | |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()closing brackets hit enter |
Line 79: | Line 79: | ||
|- | |- | ||
| 2:57 | | 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. | + | | The dtype=type within bracket int() closing bracket 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 scatter() | + | | Now in-order to generate the scatter graph we will use the function scatter()closing brackets |
|- | |- | ||
|3:18 | |3:18 | ||
− | |Type scatter within bracket year comma profit and hit enter | + | |Type scatter within closing bracket year comma profit and hit enter |
|- | |- | ||
Line 118: | Line 118: | ||
|- | |- | ||
| 5:11 | | 5:11 | ||
− | | We can plot the pie chart using the function pie() | + | | We can plot the pie chart using the function pie()closing brackets |
|- | |- |
Revision as of 15:22, 9 October 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()closing brackets hit enter
|
2:52 | By default loadtxt converts the value to float. |
2:57 | The dtype=type within bracket int() closing bracket 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()closing brackets |
3:18 | Type scatter within closing 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()closing brackets |
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! |