4 |
4 |
5 {{{ Show the slide containing the outline }}} |
5 {{{ Show the slide containing the outline }}} |
6 |
6 |
7 In this tutorial, we will learn how to draw more than one plot, how to |
7 In this tutorial, we will learn how to draw more than one plot, how to |
8 add legends to each plot to indicate what each plot represents. We |
8 add legends to each plot to indicate what each plot represents. We |
9 will also learn how to switch between the plots and creating multiple |
9 will also learn how to switch between the plots and create multiple |
10 plots with different regular axes which are also called as subplots. |
10 plots with different regular axes which are also called as subplots. |
|
11 |
|
12 .. #[Nishanth]: See diff - edited a grammatical mistake |
11 |
13 |
12 {{{ Shift to terminal and start ipython -pylab }}} |
14 {{{ Shift to terminal and start ipython -pylab }}} |
13 |
15 |
14 To begin with let us start ipython with pylab, by typing:: |
16 To begin with let us start ipython with pylab, by typing:: |
15 |
17 |
23 x = linspace(0, 50, 10) |
25 x = linspace(0, 50, 10) |
24 |
26 |
25 linspace command creates 10 points in the interval between 0 and 50 |
27 linspace command creates 10 points in the interval between 0 and 50 |
26 both inclusive. We assign these values to a variable called x. |
28 both inclusive. We assign these values to a variable called x. |
27 |
29 |
|
30 .. #[Nishanth]: pre requisite for this LO is basic plotting which |
|
31 covers linspace and plot. So you may not need to |
|
32 specify all that again. But not a problem if it is |
|
33 there also. |
|
34 |
28 Now let us draw a plot simple sine plot using these points:: |
35 Now let us draw a plot simple sine plot using these points:: |
29 |
36 |
30 plot(x, sin(x)) |
37 plot(x, sin(x)) |
31 |
38 |
32 This should give us a nice sine plot. |
39 This should give us a nice sine plot. |
33 |
40 |
34 {{{ Switch to the plot window }}} |
41 {{{ Switch to the plot window }}} |
35 |
42 |
36 Oh! wait! Is that a nice sine plot? Does a sine plot actually look |
43 Oh! wait! Is that a nice sine plot? Does a sine plot actually look |
37 like that? We know that a sine plot is a smooth curve is it not? What |
44 like that? We know that a sine plot is a smooth curve. Is it not? What |
38 really caused this? |
45 really caused this? |
|
46 |
|
47 .. #[Nishanth]: See diff |
39 |
48 |
40 {{{ pause for a while }}} |
49 {{{ pause for a while }}} |
41 |
50 |
42 A small investigation on linspace tells us that we chose too few |
51 A small investigation on linspace tells us that we chose too few |
43 points in a large interval between 0 and 50 for the curve to be |
52 points in a large interval between 0 and 50 for the curve to be |
44 smooth. So now let us use linspace again to get 500 points between 0 |
53 smooth. So now let us use linspace again to get 500 points between 0 |
45 and 100 and draw the sine plot |
54 and 100 and draw the sine plot |
|
55 |
|
56 .. #[Nishanth]: Here specify that when we do plot(x, sin(x) |
|
57 it is actually plotting two sets of points |
|
58 and not analytical functions. Hence the sharp |
|
59 curve. |
46 |
60 |
47 {{{ Switch to ipython andtype }}} :: |
61 {{{ Switch to ipython andtype }}} :: |
48 |
62 |
49 y = linspace(0, 50, 500) |
63 y = linspace(0, 50, 500) |
50 plot(y, sin(y)) |
64 plot(y, sin(y)) |
76 {{{ Switch to plot window }}} |
90 {{{ Switch to plot window }}} |
77 |
91 |
78 Now we have two plots, a sine plot and a cosine plot one overlaid upon |
92 Now we have two plots, a sine plot and a cosine plot one overlaid upon |
79 the other. |
93 the other. |
80 |
94 |
|
95 .. #[Nishanth]: figure(1) and figure(2) give two different plots. |
|
96 The remaining script moves on the fact that they |
|
97 give overlaid plots which is not the case. |
|
98 So clear the figure and plot cos and sin without |
|
99 introducing figure command. Then introduce legend |
|
100 and finish off the everything on legend. |
|
101 Then introduce figure command. |
|
102 |
81 {{{ Have both plot window and ipython side by side }}} |
103 {{{ Have both plot window and ipython side by side }}} |
82 |
104 |
83 The figure command takes an integer as an argument which is the serial |
105 The figure command takes an integer as an argument which is the serial |
84 number of the plot. This selects the corresponding plot. All the plot |
106 number of the plot. This selects the corresponding plot. All the plot |
85 commands we run after this are applied to the selected plot. In this |
107 commands we run after this are applied to the selected plot. In this |
104 legend command does this for us |
126 legend command does this for us |
105 |
127 |
106 {{{ Switch to ipython }}}:: |
128 {{{ Switch to ipython }}}:: |
107 |
129 |
108 legend(['sin(x)', 'cos(x)']) |
130 legend(['sin(x)', 'cos(x)']) |
|
131 |
|
132 .. #[Nishanth]: This legend may go up in the script. May be before |
|
133 introducing the figure command itself. |
109 |
134 |
110 The legend command takes a single list of parameters where each |
135 The legend command takes a single list of parameters where each |
111 parameter is the text indicating the plots in the order of their |
136 parameter is the text indicating the plots in the order of their |
112 serial number. |
137 serial number. |
113 |
138 |
170 automatically erased. It is clear from the two subplots that both have |
195 automatically erased. It is clear from the two subplots that both have |
171 different regular axes. For the cosine plot x-axis varies from 0 to |
196 different regular axes. For the cosine plot x-axis varies from 0 to |
172 100 and y-axis varies from 0 to 1 where as for the parabolic plot the |
197 100 and y-axis varies from 0 to 1 where as for the parabolic plot the |
173 x-axis varies from 0 to 10 and y-axis varies from 0 to 100 |
198 x-axis varies from 0 to 10 and y-axis varies from 0 to 100 |
174 |
199 |
|
200 .. #[Nishanth]: stress on the similarity between subplot and figure commands |
|
201 |
175 {{{ Show summary slide }}} |
202 {{{ Show summary slide }}} |
|
203 |
|
204 .. #[Nishanth]: Exercises are missing in the script |
|
205 one exercise for overlaid plot and legend |
|
206 one for figure command |
|
207 one for subplot must do |
176 |
208 |
177 This brings us to the end of another session. In this tutorial session |
209 This brings us to the end of another session. In this tutorial session |
178 we learnt |
210 we learnt |
179 |
211 |
180 * How to draw multiple plots which are overlaid |
212 * How to draw multiple plots which are overlaid |
182 * how to switch between the plots and perform some operations on each |
214 * how to switch between the plots and perform some operations on each |
183 of them like saving the plots |
215 of them like saving the plots |
184 * the legend command and |
216 * the legend command and |
185 * creating and switching between subplots |
217 * creating and switching between subplots |
186 |
218 |
|
219 .. #[Nishanth]: legend command can be told right after overlaid plots |
|
220 |
187 {{{ Show the "sponsored by FOSSEE" slide }}} |
221 {{{ Show the "sponsored by FOSSEE" slide }}} |
188 |
222 |
189 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
223 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
190 |
224 |
191 Hope you have enjoyed and found it useful. |
225 Hope you have enjoyed and found it useful. |
192 Thankyou |
226 Thankyou |
193 |
227 |
194 .. Author : Madhu |
228 .. Author : Madhu |
195 Internal Reviewer 1 : [potential reviewer: Puneeth] |
229 Internal Reviewer 1 : [potential reviewer: Puneeth] |
196 Internal Reviewer 2 : [potential reviewer: Nishanth] |
230 Internal Reviewer 2 : Nishanth |
197 External Reviewer : |
231 External Reviewer : |
198 |
232 |