Narration 1 00:00:01 --> 00:00:05 Hello Friends and welcome to the tutorial on Other types of plots 2 00:00:06 --> 00:00:09 Till now we have seen only one kind of plotting. 3 00:00:10 --> 00:00:15 Hence in this tutorial we will be looking at some more kinds of plots. 4 00:00:16 --> 00:00:28 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

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

y = 5 into x into 3

50 00:09:23 --> 00:09:27 Here is the syntax of the log-log function. 51 00:09:28 --> 00:09:33 Now we can plot the log-log chart using loglog()function, 52 00:09:34 --> 00:09:47 Type loglog within brackets x comma y hit enter 53 00:09:48 --> 00:09:56 To understand the difference between a normal plot and a log-log plot let us create another plot using the function plot. 54 00:09:57 --> 00:10:23 figure within brackets 2 THen type plot within brackets x comma y 55 00:10:24 --> 00:10:32 The difference is clear.So that was log-log() plot. 56 00:10:33 --> 00:10:42 Now we will see few more plots and also see how to access help of matplotlib over the Internet. 57 00:10:43 --> 00:10:54 Help about matplotlib can be obtained from matplotlib.sourceforge.net/contents.html 58 00:10:55 --> 00:11:12 More plots can be seen at matplotlib.sourceforge.net slash users slash screenshots.html and also at matplotlib.sourceforge.net slash gallery.html 59 00:11:13 --> 00:11:19 This brings us to the end of this tutorial. In this tutorial we learnt to, 60 00:11:20 --> 00:11:21 Plot a scatter plot using scatter() function 61 00:11:22 --> 00:11:24 Plot a pie chart using pie() function 62 00:11:25 --> 00:11:27 Plot a bar chart using bar() function 63 00:11:28 --> 00:11:32 Plot a log-log graph using loglog() function 64 00:11:33 --> 00:11:41 Access the matplotlib online help.Thank you. 65 00:11:42 --> 00:11:45 So there are few some self assessment questions for you to solve. 66 00:11:46 --> 00:12:03 scatter x comma y comma color=blue marker= d and plot x comma y comma color=b comma marker= d) does exactly the same. 67 00:12:04 --> 00:12:06 Is True or False? 68 00:12:07 --> 00:12:14 What statement can be issued to generate a bar chart with vertical line hatching. 69 00:12:15 --> 00:12:26 bar within function x comma y comma color=in single quote w comma hatch= slash 70 00:12:27 --> 00:12:37 bar within bracket x comma y comma fill=False comma hatch=slash slash 71 00:12:38 --> 00:12:51 bar within bracket x comma y comma fill=False comma hatch=in single quote 72 00:12:52 --> 00:13:01 bar within bracket x comma y comma color= within quote w comma hatch=single quote 73 00:13:02 --> 00:13:05 And now the answers, 74 00:13:06 --> 00:13:08 False. 75 00:13:09 --> 00:13:12 Both functions do not produce the same kind of plot. 76 00:13:13 --> 00:13:30 bar x comma y comma fill=False comma hatch=bar is the correct option to generate a bar chart with vertical line hatching. 77 00:13:31 --> 00:13:33 Hope you have enjoyed this tutorial and found it useful. 78 00:13:34 --> 00:13:39 Thank you!