Python/C2/Other-types-of-plots/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:01 Hello Friends and welcome to the tutorial on Other types of plots
00:06 Till now we have seen only one kind of plotting.
00:10 Hence in this tutorial we will be looking at some more kinds of plots.
00:16 At the end of this tutorial, you will be able to

Create scatter plot Create pie charts Create bar charts Create log-log plots Use the matplotlib help

00:29 So let us begin with scatter plot
00:33 Before beginning this tutorial,we would suggest you to complete the tutorial on "Loading data from files" and "Plotting data".
00: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.
00:54 This kind of plot is also called a scatter chart, a scatter diagram or a scatter graph.
01:01 Before we proceed further , start your IPython interpreter
01:06 So type ipython hypen pylab
01:13 Plot a scatter plot showing the percentage profit of a company A from the year 2000-2010.
01:22 The data for the same is available in the file company-a-data.txt.
01:33 Type cat space slash home slash fossee slash other-plot slash company-a-data.txt (enter)
01: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.
02:02 To produce the scatter plot, we first need to load the data from the file using loadtxt command.
02: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
02:52 By default loadtxt converts the value to float.
02: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.
03:11 Now in-order to generate the scatter graph we will use the function scatter()closing brackets
03:18 Type scatter within closing bracket year comma profit and hit enter
03: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.
03:57 Plot a scatter plot of the same data in company-a-data.txt with red diamond markers.
04:09 Pause the video here, try out the following exercise and resume the video.
04:17 Now let us see another kind of plot, the pie chart, for the same data.
04:40 A pie chart or a circle graph is a circular chart divided into sectors, illustrating proportion.
04:49 Plot a pie chart representing the profit percentage of company A, with the same data from file company-a-data.txt.
05:00 So let us reuse the data we have loaded from the file previously.
05:11 We can plot the pie chart using the function pie()closing brackets
05:15 So Type pie within bracket profit comma labels=year
05:29 Notice that we passed two arguments to the function pie().
05:33 First one the values and the next one the set of labels to be used in the pie chart.
05: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.
05:58 Pause the video here, try out the following exercise and resume the video.
06:05 Now let us move on to the bar charts.
06:08 A bar chart or bar graph is a chart with rectangular bars with lengths proportional to the values that they represent.
06:19 Plot a bar chart representing the profit percentage of company A, with the same data from file company-a-data.txt.
06:30 So let us reuse the data we have loaded from the file previously.
06:34 We can plot the bar chart using the function bar() and hit enter.
06:44 So inside that bracket you can put bar ( year , profit )
06: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.
07:05 Plot a bar chart which is not filled and which is hatched with 45 degree slanting lines as shown in the image.
07:17 The data for the chart may be obtained from the file company-a-data.txt
07:26 Type bar within bracket year comma profit comma fill=False comma hatch= within single quote slashhit enter
08:05 Now let us move on to the log-log plot.
08: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.
08: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
08:38 Plot a log-log chart of y=5 into x3for x from 1-20.
08:49 Before we actually plot let us calculate the points needed for that.
08:54 x = linspace within brackets 1 comma 20 comma 100

y = 5 into x into 3

09:23 Here is the syntax of the log-log function.
09:28 Now we can plot the log-log chart using loglog()function,
09:34 Type loglog within brackets x comma y hit enter
09:48 To understand the difference between a normal plot and a log-log plot let us create another plot using the function plot.
09: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 Plot a scatter plot using scatter() function
11:22 Plot a pie chart using pie() function
11:25 Plot a bar chart using bar() function
11:28 Plot a log-log graph using loglog() function
11:33 Access the matplotlib online help.Thank you.
11:42 So there are few some self assessment questions for you to solve.
11:46 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 What statement can be issued to generate a bar chart with vertical line hatching.
12:15 bar within function x comma y comma color=in single quote w comma hatch= slash
12:27 bar within bracket x comma y comma fill=False comma hatch=slash slash
12:38 bar within bracket x comma y comma fill=False comma hatch=in single quote
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 False.
13:09 Both functions do not produce the same kind of plot.
13:13 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!

Contributors and Content Editors

Gaurav, Jyotisolanki, Minal, PoojaMoolya, Ranjana, Sneha