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