equal
deleted
inserted
replaced
7 In this tutorial, we shall look at how to modify the colour, thickness and |
7 In this tutorial, we shall look at how to modify the colour, thickness and |
8 linestyle of the plot. We shall then learn how to add title to the plot and |
8 linestyle of the plot. We shall then learn how to add title to the plot and |
9 then look at adding labels to x and y axes. we shall also look at adding |
9 then look at adding labels to x and y axes. we shall also look at adding |
10 annotations to the plot. |
10 annotations to the plot. |
11 |
11 |
12 Let us start ipython with pylab loaded, by typing |
12 Let us start ipython with pylab loaded, by typing on the terminal |
|
13 |
|
14 {{{ shift to terminal and type ipython -pylab }}} |
|
15 |
13 :: |
16 :: |
14 |
17 |
15 ipython -pylab |
18 ipython -pylab |
16 |
|
17 on the terminal |
|
18 |
|
19 {{{ shift to terminal and type ipython -pylab }}} |
|
20 |
19 |
21 #[madhu: I feel the instructions should precede the actual action, |
20 #[madhu: I feel the instructions should precede the actual action, |
22 since while recording we need to know before hand what we need to do] |
21 since while recording we need to know before hand what we need to do] |
23 |
22 |
24 We shall first make a simple plot and start with decorating it. |
23 We shall first make a simple plot and start decorating it. |
25 |
24 |
26 .. #[madhu: start decorating it should be fine, with is not necessary] |
25 .. #[madhu: start decorating it should be fine, with is not necessary] |
27 |
26 |
28 :: |
27 :: |
29 |
28 |
31 plot(x, sin(x)) |
30 plot(x, sin(x)) |
32 |
31 |
33 .. #[madhu: Standard is to choose between -50 to 50 or 0 to 50 with 100 |
32 .. #[madhu: Standard is to choose between -50 to 50 or 0 to 50 with 100 |
34 points right?] |
33 points right?] |
35 |
34 |
36 As you can see, the default colour and the default thickness of the |
35 As we can see, the default colour and the default thickness of the |
37 line is as decided by pylab. Wouldn't be nice if we could control |
36 line is as decided by pylab. Wouldn't be nice if we could control |
38 these parameters in the plot? Yes, this is possible by passing additional |
37 these parameters in the plot? This is possible by passing additional |
39 arguments to the plot command. |
38 arguments to the plot command. |
40 |
39 |
41 .. #[[Anoop: I think it will be good to rephrase the sentence]] |
40 .. #[[Anoop: I think it will be good to rephrase the sentence]] |
42 .. #[madhu: Why "you" here? Shouldn't this be "we" as decided? Also I |
41 .. #[madhu: Why "you" here? Shouldn't this be "we" as decided? Also I |
43 added "the default" check the diff] |
42 added "the default" check the diff] |
82 {{{ continue from paused state }}} |
81 {{{ continue from paused state }}} |
83 |
82 |
84 A combination of colour and linewidth would do the job for us. Hence |
83 A combination of colour and linewidth would do the job for us. Hence |
85 :: |
84 :: |
86 |
85 |
|
86 clf() |
87 plot(x, sin(x), 'b', linewidth=3) |
87 plot(x, sin(x), 'b', linewidth=3) |
88 |
88 |
89 .. #[[Anoop: add clf()]] |
89 .. #[[Anoop: add clf()]] |
90 |
90 |
91 produces the required plot |
91 produces the required plot |
120 |
120 |
121 plot? |
121 plot? |
122 |
122 |
123 {{{ Run through the documentation and show the options available }}} |
123 {{{ Run through the documentation and show the options available }}} |
124 |
124 |
|
125 {{{ Show the options available for line style and colors }}} |
|
126 |
125 .. #[Madhu: The script needs to tell what needs to be shown or |
127 .. #[Madhu: The script needs to tell what needs to be shown or |
126 explained.] |
128 explained.] |
127 |
129 |
128 {{{ Pause here and try out the following exercises }}} |
130 {{{ Pause here and try out the following exercises }}} |
129 |
131 |
142 |
144 |
143 produces the required plot. |
145 produces the required plot. |
144 |
146 |
145 {{{ Pause here and try out the following exercises }}} |
147 {{{ Pause here and try out the following exercises }}} |
146 |
148 |
147 %% 3 %% Produce a plot of tangent curve with red dashed line and linewidth 3 |
149 %% 3 %% Plot the curve of x vs tan(x) in red dashed line and linewidth 3 |
148 |
150 |
149 {{{ continue from paused state }}} |
151 {{{ continue from paused state }}} |
150 |
152 |
151 .. #[Madhu: I did not understand the question] |
153 .. #[Madhu: I did not understand the question] |
152 |
154 |
261 annotate("local maxima", xy=(2, -1)) |
263 annotate("local maxima", xy=(2, -1)) |
262 |
264 |
263 {{{ Show the annotation that has appeared on the plot }}} |
265 {{{ Show the annotation that has appeared on the plot }}} |
264 |
266 |
265 As you can see, the first argument to =annotate= command is the name we would |
267 As you can see, the first argument to =annotate= command is the name we would |
266 like to mark the point as and the argument after xy= is the point at which the |
268 like to mark the point as and the second argument is the co-ordinates of the |
267 name should appear. |
269 point at which the name should appear. It is a sequence containing two numbers. |
|
270 The first is x co-ordinate and second is y co-ordinate. |
268 |
271 |
269 .. #[[Anoop: I think we should tell explicitely that xy takes a |
272 .. #[[Anoop: I think we should tell explicitely that xy takes a |
270 sequence or a tuple]] |
273 sequence or a tuple]] |
271 .. #[Madhu: Agreed to what anoop says and also that xy= is the point |
274 .. #[Madhu: Agreed to what anoop says and also that xy= is the point |
272 part should be rephrased I think.] |
275 part should be rephrased I think.] |