15 Hello and welcome to the tutorial other type of plots. |
15 Hello and welcome to the tutorial other type of plots. |
16 |
16 |
17 {{{ show the outline slide }}} |
17 {{{ show the outline slide }}} |
18 |
18 |
19 In this tutorial we will cover scatter plot, pie chart, bar chart and |
19 In this tutorial we will cover scatter plot, pie chart, bar chart and |
20 log plot. We will also see few other plots and also introduce you to |
20 loglog plot. We will also see few other plots and also introduce you to |
21 the matplotlib help. |
21 the matplotlib help. |
22 |
22 |
23 Let us start with scatter plot. |
23 Let us start with scatter plot. |
24 |
24 |
25 {{{ switch to the next slide }}} |
25 {{{ switch to the next slide, scatter plot }}} |
26 |
26 |
27 In a scatter plot, the data is displayed as a collection of points, |
27 In a scatter plot, the data is displayed as a collection of points, |
28 each having the value of one variable determining the position on the |
28 each having the value of one variable determining the position on the |
29 horizontal axis and the value of the other variable determining the |
29 horizontal axis and the value of the other variable determining the |
30 position on the vertical axis. This kind of plot is also called a |
30 position on the vertical axis. This kind of plot is also called a |
53 profit percentages. |
53 profit percentages. |
54 |
54 |
55 {{{ close the file and switch to the terminal }}} |
55 {{{ close the file and switch to the terminal }}} |
56 |
56 |
57 To produce the scatter plot first we need to load the data from the |
57 To produce the scatter plot first we need to load the data from the |
58 file using ``loadtxt``. We learned in one of the previous sessions, |
58 file using ``loadtxt``. We learned it in one of the previous sessions, |
59 and it can be done as :: |
59 and it can be done as :: |
60 |
60 |
61 year,profit = |
61 year,profit = |
62 loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int())) |
62 loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int())) |
|
63 |
|
64 {{{ switch to next slide, ``scatter`` function }}} |
63 |
65 |
64 Now in-order to generate the scatter graph we will use the function |
66 Now in-order to generate the scatter graph we will use the function |
65 ``scatter()`` |
67 ``scatter()`` |
66 :: |
68 :: |
67 |
69 |
73 |
75 |
74 {{{ switch to the next slide which has the problem statement of |
76 {{{ switch to the next slide which has the problem statement of |
75 problem to be tried out }}} |
77 problem to be tried out }}} |
76 |
78 |
77 Now here is a question for you to try out, plot the same data with red |
79 Now here is a question for you to try out, plot the same data with red |
78 diamonds. |
80 diamonds markers. |
79 |
81 |
80 **Clue** - *try scatter? in your ipython interpreter* |
82 .. **Clue** - *try scatter? in your ipython interpreter* |
|
83 |
|
84 Pause here and solve the question before moving on. |
81 |
85 |
82 .. scatter(year,profit,color='r',marker='d') |
86 .. scatter(year,profit,color='r',marker='d') |
83 |
87 |
84 Now let us move on to pie chart. |
88 Now let us move on to pie chart. |
85 |
89 |
93 |
97 |
94 Plot a pie chart representing the profit percentage of company A, with |
98 Plot a pie chart representing the profit percentage of company A, with |
95 the same data from file ``company-a-data.txt``. So let us reuse the |
99 the same data from file ``company-a-data.txt``. So let us reuse the |
96 data we have loaded from the file previously. |
100 data we have loaded from the file previously. |
97 |
101 |
|
102 {{{ switch to next slide, ``pie()`` function }}} |
|
103 |
98 We can plot the pie chart using the function ``pie()``. |
104 We can plot the pie chart using the function ``pie()``. |
99 :: |
105 :: |
100 |
106 |
101 pie(profit,labels=year) |
107 pie(profit,labels=year) |
102 |
108 |
109 |
115 |
110 Now here is a question for you to try out, plot a pie chart with the |
116 Now here is a question for you to try out, plot a pie chart with the |
111 same data with colors for each wedges as white, red, black, magenta, |
117 same data with colors for each wedges as white, red, black, magenta, |
112 yellow, blue, green, cyan, yellow, magenta and blue respectively. |
118 yellow, blue, green, cyan, yellow, magenta and blue respectively. |
113 |
119 |
114 **Clue** - *try pie? in your ipython interpreter* |
120 .. **Clue** - *try pie? in your ipython interpreter* |
|
121 |
|
122 Pause here and solve the question before moving on. |
115 |
123 |
116 .. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b')) |
124 .. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b')) |
117 |
125 |
118 {{{ switch to the slide which says about bar chart }}} |
126 {{{ switch to the slide which says about bar chart }}} |
119 |
127 |
120 Now let us move on to bar chart. A bar chart or bar graph is a chart |
128 Now let us move on to bar chart. A bar chart or bar graph is a chart |
121 with rectangular bars with lengths proportional to the values that |
129 with rectangular bars with lengths proportional to the values that |
122 they represent. |
130 they represent. |
123 |
131 |
124 {{{ switch to the slide showing the problem statement of third |
132 {{{ switch to the slide showing the problem statement of fifth |
125 exercise question }}} |
133 exercise question }}} |
126 |
134 |
127 Plot a bar chart representing the profit percentage of company A, with |
135 Plot a bar chart representing the profit percentage of company A, with |
128 the same data from file ``company-a-data.txt``. |
136 the same data from file ``company-a-data.txt``. |
129 |
137 |
130 So let us reuse the data we have loaded from the file previously. |
138 So let us reuse the data we have loaded from the file previously. |
|
139 |
|
140 {{{ switch to the next slide, ``bar()`` function }}} |
131 |
141 |
132 We can plot the bar chart using the function ``bar()``. |
142 We can plot the bar chart using the function ``bar()``. |
133 :: |
143 :: |
134 |
144 |
135 bar(year,profit) |
145 bar(year,profit) |
141 {{{ switch to the next slide which has the problem statement of |
151 {{{ switch to the next slide which has the problem statement of |
142 problem to be tried out }}} |
152 problem to be tried out }}} |
143 |
153 |
144 Now here is a question for you to try, plot a bar chart which is not |
154 Now here is a question for you to try, plot a bar chart which is not |
145 filled and which is hatched with 45\ :sup:`o` slanting lines as shown |
155 filled and which is hatched with 45\ :sup:`o` slanting lines as shown |
146 in the image in the slide. |
156 in the image in the slide. The data for the chart may be obtained from |
147 |
157 the file ``company-a-data.txt``. |
148 **Clue** - *try bar? in your ipython interpreter* |
158 |
|
159 .. **Clue** - *try bar? in your ipython interpreter* |
149 |
160 |
150 .. bar(year,profit,fill=False,hatch='/') |
161 .. bar(year,profit,fill=False,hatch='/') |
151 |
162 |
152 {{{ switch to the slide which says about bar chart }}} |
163 {{{ switch to the slide which says about log-log graph }}} |
153 |
164 |
154 Now let us move on to log-log plot. A log-log graph or log-log plot is |
165 Now let us move on to log-log plot. A log-log graph or log-log plot is |
155 a two-dimensional graph of numerical data that uses logarithmic scales |
166 a two-dimensional graph of numerical data that uses logarithmic scales |
156 on both the horizontal and vertical axes. Because of the nonlinear |
167 on both the horizontal and vertical axes. Because of the nonlinear |
157 scaling of the axes, a function of the form y = ax\ :sup:`b` will |
168 scaling of the axes, a function of the form y = ax\ :sup:`b` will |
198 |
211 |
199 More plots can be seen at |
212 More plots can be seen at |
200 matplotlib.sourceforge.net/users/screenshots.html and also at |
213 matplotlib.sourceforge.net/users/screenshots.html and also at |
201 matplotlib.sourceforge.net/gallery.html |
214 matplotlib.sourceforge.net/gallery.html |
202 |
215 |
203 {{{ switch to recap slide }}} |
216 {{{ switch to summary slide }}} |
204 |
217 |
205 Now we have come to the end of this tutorial. We have covered scatter |
218 Now we have come to the end of this tutorial. We have covered scatter |
206 plot, pie chart, bar chart, log-log plot and also saw few other plots |
219 plot, pie chart, bar chart, log-log plot and also saw few other plots |
207 and covered how to access the matplotlib online help. |
220 and covered how to access the matplotlib online help. |
208 |
221 |