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