author | amit |
Thu, 23 Sep 2010 12:46:52 +0530 | |
changeset 202 | 069d4e86207e |
parent 191 | 08b2cb94c57c |
child 193 | 0d175627e828 |
permissions | -rw-r--r-- |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
1 |
Hello friends and welcome to the tutorial on Embellishing Plots. |
129 | 2 |
|
3 |
{{{ Show the slide containing title }}} |
|
4 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
5 |
{{{ Show the slide containing the outline }}} |
129 | 6 |
|
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 |
|
9 |
then look at adding labels to x and y axes. we shall also look at adding |
|
10 |
annotations to the plot. |
|
11 |
||
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
12 |
Let us start ipython with pylab loaded, by typing on the terminal |
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
13 |
|
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
14 |
{{{ shift to terminal and type ipython -pylab }}} |
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
15 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
16 |
:: |
129 | 17 |
|
18 |
ipython -pylab |
|
19 |
||
190
6dcc77582e26
made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents:
173
diff
changeset
|
20 |
.. #[madhu: I feel the instructions should precede the actual action, |
191 | 21 |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
22 |
since while recording we need to know before hand what we need to do] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
23 |
|
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
24 |
We shall first make a simple plot and start decorating it. |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
25 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
26 |
.. #[madhu: start decorating it should be fine, with is not necessary] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
27 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
28 |
:: |
129 | 29 |
|
30 |
x = linspace(-2, 4, 20) |
|
31 |
plot(x, sin(x)) |
|
32 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
33 |
.. #[madhu: Standard is to choose between -50 to 50 or 0 to 50 with 100 |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
34 |
points right?] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
35 |
|
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
36 |
As we can see, the default colour and the default thickness of the |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
37 |
line is as decided by pylab. Wouldn't be nice if we could control |
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
38 |
these parameters in the plot? This is possible by passing additional |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
39 |
arguments to the plot command. |
129 | 40 |
|
159 | 41 |
.. #[[Anoop: I think it will be good to rephrase the sentence]] |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
42 |
.. #[madhu: Why "you" here? Shouldn't this be "we" as decided? Also I |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
43 |
added "the default" check the diff] |
159 | 44 |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
45 |
The additional argument that we shall be passing in here now is the |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
46 |
colour argument. We shall first clear the figure and plot the same in |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
47 |
red colour. Hence |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
48 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
49 |
.. #[Madhu: Note the diff for changes] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
50 |
:: |
129 | 51 |
|
52 |
clf() |
|
53 |
plot(x, sin(x), 'r') |
|
54 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
55 |
As we can see we have the same plot but now in red colour. |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
56 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
57 |
.. #[Madhu: diff again] |
129 | 58 |
|
59 |
To alter the thickness of the line, we use the =linewidth= argument in the plot |
|
159 | 60 |
command. Hence |
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
61 |
:: |
129 | 62 |
|
63 |
plot(x, cos(x), linewidth=2) |
|
64 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
65 |
produces a plot with a thicker line, to be more precise plot with line |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
66 |
thickness 2. |
129 | 67 |
|
159 | 68 |
.. #[[Anoop: I guess it will be good if you say that it affects the |
69 |
same plot, as you have not cleared the figure]] |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
70 |
.. #[Madhu: To Anoop, not necessary I feel since they can see it?] |
159 | 71 |
|
72 |
{{{ Show the plot and compare the sine and cos plots }}} |
|
129 | 73 |
|
74 |
{{{ Pause here and try out the following exercises }}} |
|
75 |
||
159 | 76 |
.. #[[Anoop: is the above a context switch for the person who does the |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
77 |
recording, other wise if it an instruction to the person viewing |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
78 |
the video, then I guess the three braces can be removed.]] |
159 | 79 |
|
129 | 80 |
%% 1 %% Plot sin(x) in blue colour and with linewidth as 3 |
81 |
||
82 |
{{{ continue from paused state }}} |
|
83 |
||
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
84 |
A combination of colour and linewidth would do the job for us. Hence |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
85 |
:: |
129 | 86 |
|
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
87 |
clf() |
129 | 88 |
plot(x, sin(x), 'b', linewidth=3) |
89 |
||
159 | 90 |
.. #[[Anoop: add clf()]] |
91 |
||
129 | 92 |
produces the required plot |
93 |
||
190
6dcc77582e26
made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents:
173
diff
changeset
|
94 |
.. #[Nishanth]: I could not think of a SIMPLE recipe approach for |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
95 |
introducing linestyle. Hence the naive approach. |
129 | 96 |
|
159 | 97 |
.. #[[Anoop: I guess the recipe is fine, but would be better if you |
98 |
add the problem statement rather than just saying "let's do a simple |
|
99 |
plot"]] |
|
100 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
101 |
.. #[Madhu: It is good enough.] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
102 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
103 |
Occasionally we would also want to alter the style of line. Sometimes |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
104 |
all we want is just a bunch of points not joined. This is possible by |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
105 |
passing the linestyle argument along with or instead of the colour |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
106 |
argument. Hence :: |
129 | 107 |
|
108 |
clf() |
|
109 |
plot(x, sin(x), '.') |
|
110 |
||
111 |
produces a plot with only points. |
|
112 |
||
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
113 |
To produce the same plot but now in blue colour, we do |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
114 |
:: |
129 | 115 |
|
116 |
clf() |
|
117 |
plot(x, sin(x), 'b.') |
|
118 |
||
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
119 |
Other available options can be seen in the documentation of plot. |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
120 |
:: |
129 | 121 |
|
122 |
plot? |
|
123 |
||
124 |
{{{ Run through the documentation and show the options available }}} |
|
125 |
||
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
126 |
{{{ Show the options available for line style and colors }}} |
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
127 |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
128 |
.. #[Madhu: The script needs to tell what needs to be shown or |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
129 |
explained.] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
130 |
|
129 | 131 |
{{{ Pause here and try out the following exercises }}} |
132 |
||
159 | 133 |
.. #[[Anoop: same question as above, should it be read out?]] |
134 |
||
129 | 135 |
%% 2 %% Plot the sine curve with green filled circles. |
136 |
||
137 |
{{{ continue from paused state }}} |
|
138 |
||
139 |
All we have to do is use a combination of linestyle and colour to acheive this. |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
140 |
Hence |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
141 |
:: |
129 | 142 |
|
143 |
clf() |
|
144 |
plot(x, cos(x), 'go') |
|
145 |
||
146 |
produces the required plot. |
|
147 |
||
148 |
{{{ Pause here and try out the following exercises }}} |
|
149 |
||
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
150 |
%% 3 %% Plot the curve of x vs tan(x) in red dashed line and linewidth 3 |
129 | 151 |
|
152 |
{{{ continue from paused state }}} |
|
153 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
154 |
.. #[Madhu: I did not understand the question] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
155 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
156 |
Now that we know how to produce a bare minimum plot with colour, style |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
157 |
and thickness of our interest, we shall look at decorating the plot. |
129 | 158 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
159 |
Let us start with a plot of the function -x^2 + 4x - 5. |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
160 |
:: |
129 | 161 |
|
162 |
plot(x, -x*x + 4*x - 5, 'r', linewidth=2) |
|
163 |
||
164 |
{{{ Show the plot window and switch back to terminal }}} |
|
165 |
||
166 |
We now have the plot in a colour and linewidth of our interest. As you can see, |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
167 |
the figure does not have any description describing the plot. |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
168 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
169 |
.. #[Madhu: Added "not". See the diff] |
129 | 170 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
171 |
We will now add a title to the plot by using the =title= command. |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
172 |
:: |
129 | 173 |
|
174 |
title("Parabolic function -x^2+4x-5") |
|
175 |
||
176 |
{{{ Show the plot window and point to the title }}} |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
177 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
178 |
The figure now has a title which describes what the plot is. The |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
179 |
=title= command as you can see, takes a string as an argument and sets |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
180 |
the title accordingly. |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
181 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
182 |
.. #[Madhu: See the diff] |
129 | 183 |
|
184 |
The formatting in title is messed and it does not look clean. You can imagine |
|
185 |
what would be the situation if there were fractions and more complex functions |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
186 |
like log and exp. Wouldn't it be good if there was LaTex like formatting? |
129 | 187 |
|
188 |
That is also possible by adding a $ sign before and after the part of the |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
189 |
string that should be in LaTex style. |
129 | 190 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
191 |
for instance, we can use |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
192 |
:: |
129 | 193 |
|
194 |
title("Parabolic function $-x^2+4x-5$") |
|
195 |
||
196 |
and we get the polynomial formatted properly. |
|
197 |
||
190
6dcc77582e26
made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents:
173
diff
changeset
|
198 |
.. #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole |
130 | 199 |
string in LaTex style is not good |
200 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
201 |
.. #[[Anoop: I guess you can go ahead with the LaTex thing, it's |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
202 |
cool!]] |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
203 |
.. #[Madhu: Instead of saying LaTeX style you can say Typeset math |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
204 |
since that is how it is called as. I am not sure as well. It |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
205 |
doesn't really solve the purpose] |
159 | 206 |
|
129 | 207 |
{{{ Pause here and try out the following exercises }}} |
208 |
||
209 |
%% 4 %% Change the title of the figure such that the whole title is formatted |
|
210 |
in LaTex style |
|
211 |
||
212 |
{{{ continue from the paused state }}} |
|
213 |
||
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
214 |
The solution is to enclose the whole string in between $. Hence, |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
215 |
:: |
129 | 216 |
|
217 |
title("$Parabolic function -x^2+4x-5$") |
|
218 |
||
219 |
gives a title that looks neatly formatted. |
|
220 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
221 |
Although we have title, the plot is not complete without labelling x |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
222 |
and y axes. Hence we shall label x-axis to "x" and y-axis to "f(x)" :: |
129 | 223 |
|
224 |
xlabel("x") |
|
225 |
||
226 |
{{{ Switch to plot window and show the xlabel }}} |
|
227 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
228 |
As you can see, =xlabel= command takes a string as an argument, |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
229 |
similar to the =title= command and sets it as the label to x-axis. |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
230 |
|
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
231 |
.. #[See the diff] |
129 | 232 |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
233 |
Similarly, |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
234 |
:: |
129 | 235 |
|
236 |
ylabel("f(x)") |
|
237 |
||
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
238 |
sets the name of the y-axis as "f(x)" |
129 | 239 |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
240 |
{{{ Show the plot window and point to ylabel and switch back to the terminal }}} |
129 | 241 |
|
242 |
{{{ Pause here and try out the following exercises }}} |
|
243 |
||
244 |
%% 5 %% Set the x and y labels as "x" and "f(x)" in LaTex style. |
|
245 |
||
246 |
{{{ continue from paused state }}} |
|
247 |
||
248 |
Since we need LaTex style formatting, all we have to do is enclose the string |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
249 |
in between two $. Hence, |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
250 |
:: |
129 | 251 |
|
252 |
xlabel("$x$") |
|
253 |
yalbel("$f(x)$") |
|
254 |
||
255 |
does the job for us. |
|
256 |
||
257 |
{{{ Show the plot window with clean labels }}} |
|
258 |
||
259 |
The plot is now almost complete. Except that we have still not seen how to |
|
260 |
name the points. For example the point (2, -1) is the local maxima. We would |
|
138
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
261 |
like to name the point accordingly. We can do this by using |
85ed0d5d28f8
added a newline before :: so that a colon does not appear in html
nishanth
parents:
130
diff
changeset
|
262 |
:: |
129 | 263 |
|
264 |
annotate("local maxima", xy=(2, -1)) |
|
265 |
||
266 |
{{{ Show the annotation that has appeared on the plot }}} |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
267 |
|
129 | 268 |
As you can see, the first argument to =annotate= command is the name we would |
173
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
269 |
like to mark the point as and the second argument is the co-ordinates of the |
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
270 |
point at which the name should appear. It is a sequence containing two numbers. |
24289d3a4fdb
added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents:
172
diff
changeset
|
271 |
The first is x co-ordinate and second is y co-ordinate. |
129 | 272 |
|
159 | 273 |
.. #[[Anoop: I think we should tell explicitely that xy takes a |
274 |
sequence or a tuple]] |
|
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
275 |
.. #[Madhu: Agreed to what anoop says and also that xy= is the point |
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
276 |
part should be rephrased I think.] |
159 | 277 |
|
129 | 278 |
{{{ Pause here and try out the following exercises }}} |
279 |
||
280 |
%% 6 %% Make an annotation called "root" at the point (-4, 0) |
|
281 |
What happens to the first annotation ? |
|
282 |
||
283 |
{{{ continue from paused state }}} |
|
284 |
||
285 |
As we can see, every annotate command makes a new annotation on the figure. |
|
286 |
||
287 |
{{{ Show summary slide }}} |
|
288 |
||
289 |
we have looked at |
|
290 |
||
291 |
* Modifying the attributes of plot by passing additional arguments |
|
292 |
* How to add title |
|
293 |
* How to incorporate LaTex style formatting |
|
294 |
* How to label x and y axes |
|
295 |
* How to add annotations |
|
296 |
||
297 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
|
298 |
||
190
6dcc77582e26
made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents:
173
diff
changeset
|
299 |
.. #[Nishanth]: Will add this line after all of us fix on one. |
191 | 300 |
|
129 | 301 |
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
302 |
||
303 |
Hope you have enjoyed and found it useful. |
|
304 |
Thankyou |
|
305 |
||
306 |
.. Author : Nishanth |
|
159 | 307 |
Internal Reviewer 1 : Anoop |
172
438e7bae3cf3
Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
159
diff
changeset
|
308 |
Internal Reviewer 2 : Madhu |
129 | 309 |
External Reviewer : |