embellishing_a_plot.rst
author Puneeth Chaganti <punchagan@fossee.in>
Wed, 06 Oct 2010 18:56:37 +0530
changeset 224 4e0cdb5cca53
parent 214 8b08fc88d5a0
permissions -rw-r--r--
Added questions and other info to accessing-pieces-arrays LO.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
214
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     1
.. Author              : Nishanth
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     2
   Internal Reviewer 1 : Anoop
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     3
   Internal Reviewer 2 : Madhu
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     4
   External Reviewer   :
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     5
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     6
.. Prerequisites: using ``plot`` command
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
     7
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
     8
Hello friends and welcome to the tutorial on Embellishing Plots.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
     9
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    10
{{{ Show the slide containing title }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    11
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    12
{{{ Show the slide containing the outline }}}
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    13
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    14
In this tutorial, we shall look at how to modify the colour, thickness and 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    15
linestyle of the plot. We shall then learn how to add title to the plot and 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    16
then look at adding labels to x and y axes. we shall also look at adding 
214
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
    17
annotations to the plot and setting the limits of axes.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    18
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    19
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
    20
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    21
{{{ shift to terminal and type ipython -pylab }}}
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    22
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    23
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    24
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    25
    ipython -pylab
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    26
190
6dcc77582e26 made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents: 173
diff changeset
    27
.. #[madhu: I feel the instructions should precede the actual action,
191
08b2cb94c57c fixed syntax errors
Nishanth <nishanth@fossee.in>
parents: 190
diff changeset
    28
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    29
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
    30
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    31
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
    32
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    33
.. #[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
    34
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    35
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    36
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    37
    x = linspace(-2, 4, 20)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    38
    plot(x, sin(x))
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    39
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    40
.. #[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
    41
     points right?]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    42
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    43
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
    44
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
    45
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
    46
arguments to the plot command.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    47
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    48
.. #[[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
    49
.. #[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
    50
     added "the default" check the diff]
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    51
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    52
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
    53
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
    54
red colour. Hence
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: Note the diff for changes]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    57
 ::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    58
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    59
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    60
    plot(x, sin(x), 'r')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    61
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    62
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
    63
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    64
.. #[Madhu: diff again]
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    65
193
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
    66
To alter the thickness of the line, we use the ``linewidth`` argument in the plot
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    67
command. Hence
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    68
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    69
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    70
    plot(x, cos(x), linewidth=2)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    71
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
    72
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
    73
thickness 2.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    74
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    75
.. #[[Anoop: I guess it will be good if you say that it affects the
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    76
   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
    77
.. #[Madhu: To Anoop, not necessary I feel since they can see it?]
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    78
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    79
{{{ Show the plot and compare the sine and cos plots }}}
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    80
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    81
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    82
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    83
.. #[[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
    84
   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
    85
   the video, then I guess the three braces can be removed.]]
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    86
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    87
%% 1 %% Plot sin(x) in blue colour and with linewidth as 3
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    88
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    89
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    90
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    91
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
    92
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    93
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
    94
    clf()
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    95
    plot(x, sin(x), 'b', linewidth=3)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    96
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    97
.. #[[Anoop: add clf()]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    98
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    99
produces the required plot
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   100
190
6dcc77582e26 made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents: 173
diff changeset
   101
.. #[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
   102
             introducing linestyle. Hence the naive approach.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   103
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   104
.. #[[Anoop: I guess the recipe is fine, but would be better if you
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   105
   add the problem statement rather than just saying "let's do a simple
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   106
   plot"]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   107
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   108
.. #[Madhu: It is good enough.]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   109
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   110
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
   111
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
   112
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
   113
argument. Hence ::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   114
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   115
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   116
    plot(x, sin(x), '.')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   117
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   118
produces a plot with only points.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   119
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   120
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
   121
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   122
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   123
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   124
    plot(x, sin(x), 'b.')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   125
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   126
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
   127
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   128
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   129
    plot?
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   130
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   131
{{{ Run through the documentation and show the options available }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   132
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
   133
{{{ 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
   134
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   135
.. #[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
   136
     explained.]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   137
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   138
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   139
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   140
.. #[[Anoop: same question as above, should it be read out?]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   141
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   142
%% 2 %% Plot the sine curve with green filled circles.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   143
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   144
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   145
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   146
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
   147
Hence
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   148
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   149
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   150
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   151
    plot(x, cos(x), 'go')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   152
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   153
produces the required plot.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   154
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   155
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   156
173
24289d3a4fdb added the changes suggested by anoop and madhu
Nishanth <nishanth@fossee.in>
parents: 172
diff changeset
   157
%% 3 %% Plot the curve of x vs tan(x) in red dashed line and linewidth 3
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   158
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   159
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   160
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   161
.. #[Madhu: I did not understand the question]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   162
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   163
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
   164
and thickness of our interest, we shall look at decorating the plot.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   165
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   166
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
   167
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   168
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   169
    plot(x, -x*x + 4*x - 5, 'r', linewidth=2)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   170
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   171
{{{ Show the plot window and switch back to terminal }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   172
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   173
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
   174
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
   175
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   176
.. #[Madhu: Added "not". See the diff]
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   177
193
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
   178
We will now add a title to the plot by using the ``title`` command.
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   179
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   180
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   181
    title("Parabolic function -x^2+4x-5") 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   182
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   183
{{{ 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
   184
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   185
The figure now has a title which describes what the plot is. The
193
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
   186
``title`` command as you can see, takes a string as an argument and sets
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   187
the title accordingly.
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   188
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   189
.. #[Madhu: See the diff]
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   190
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   191
The formatting in title is messed and it does not look clean. You can imagine
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   192
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
   193
like log and exp. Wouldn't it be good if there was LaTex like formatting?
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   194
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   195
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
   196
string that should be in LaTex style.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   197
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   198
for instance, we can use
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   199
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   200
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   201
    title("Parabolic function $-x^2+4x-5$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   202
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   203
and we get the polynomial formatted properly.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   204
190
6dcc77582e26 made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents: 173
diff changeset
   205
.. #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole
130
5b04f1c63b16 added a comment
nishanth
parents: 129
diff changeset
   206
             string in LaTex style is not good
5b04f1c63b16 added a comment
nishanth
parents: 129
diff changeset
   207
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   208
.. #[[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
   209
     cool!]]
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   210
.. #[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
   211
     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
   212
     doesn't really solve the purpose]
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   213
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   214
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   215
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   216
%% 4 %% Change the title of the figure such that the whole title is formatted
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   217
        in LaTex style
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   218
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   219
{{{ continue from the paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   220
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   221
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
   222
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   223
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   224
    title("$Parabolic function -x^2+4x-5$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   225
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   226
gives a title that looks neatly formatted.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   227
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   228
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
   229
and y axes. Hence we shall label x-axis to "x" and y-axis to "f(x)" ::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   230
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   231
    xlabel("x")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   232
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   233
{{{ Switch to plot window and show the xlabel }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   234
193
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
   235
As you can see, ``xlabel`` command takes a string as an argument,
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
   236
similar to the ``title`` command and sets it as the label to x-axis.
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   237
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   238
.. #[See the diff]
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   239
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   240
Similarly,
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   241
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   242
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   243
    ylabel("f(x)")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   244
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   245
sets the name of the y-axis as "f(x)"
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   246
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   247
{{{ Show the plot window and point to ylabel and switch back to the terminal }}}
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   248
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   249
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   250
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   251
%% 5 %% Set the x and y labels as "x" and "f(x)" in LaTex style.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   252
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   253
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   254
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   255
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
   256
in between two $. Hence,
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   257
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   258
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   259
    xlabel("$x$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   260
    yalbel("$f(x)$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   261
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   262
does the job for us.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   263
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   264
{{{ Show the plot window with clean labels }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   265
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   266
The plot is now almost complete. Except that we have still not seen how to 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   267
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
   268
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
   269
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   270
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   271
    annotate("local maxima", xy=(2, -1))
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   272
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   273
{{{ 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
   274
193
0d175627e828 changed = to `` so that it shows properly
Nishanth <nishanth@fossee.in>
parents: 191
diff changeset
   275
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
   276
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
   277
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
   278
The first is x co-ordinate and second is y co-ordinate.
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   279
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   280
.. #[[Anoop: I think we should tell explicitely that xy takes a
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   281
   sequence or a tuple]]
172
438e7bae3cf3 Second Review for embellishing plot.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 159
diff changeset
   282
.. #[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
   283
     part should be rephrased I think.]
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   284
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   285
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   286
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   287
%% 6 %% Make an annotation called "root" at the point (-4, 0)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   288
        What happens to the first annotation ?
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   289
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   290
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   291
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   292
As we can see, every annotate command makes a new annotation on the figure.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   293
214
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   294
Now we have everything we need to decorate a plot. but the plot would be
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   295
incomplete if we can not set the limits of axes. This is possible using the
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   296
button on the plot window.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   297
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   298
we shall look at how to get and set them from the script.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   299
::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   300
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   301
    xlim()
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   302
    ylim()
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   303
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   304
We see that ``xlim`` function returns the current x axis limits and ylim
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   305
function returns the current y-axis limits.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   306
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   307
Let us look at how to set the limits.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   308
::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   309
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   310
    xlim(-4, 5)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   311
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   312
We see the limits of x-axis are now set to -4 and 5.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   313
Similarly
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   314
::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   315
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   316
    ylim(-15, 2)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   317
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   318
sets the limits of y-axis appropriately.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   319
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   320
{{{ Pause here and try out the following exercises }}}
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   321
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   322
%% 7 %% Set the limits of axes such that the area of interest is the rectangle
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   323
        (-1, -15) and (3, 0)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   324
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   325
{{{ continue from paused state }}}
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   326
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   327
As we can see, the lower upper limits of x-axis in the question are -1 and 3.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   328
The limits of y-axis are -15 and 0.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   329
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   330
::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   331
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   332
    xlim(-1, 3)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   333
    ylim(-15, 0)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   334
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   335
Gives us the required rectangle.
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   336
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   337
{{{ Show summary slide }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   338
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   339
we have looked at 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   340
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   341
 * Modifying the attributes of plot by passing additional arguments
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   342
 * How to add title
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   343
 * How to incorporate LaTex style formatting
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   344
 * How to label x and y axes
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   345
 * How to add annotations
214
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   346
 * How to set the limits of axes
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   347
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   348
{{{ Show the "sponsored by FOSSEE" slide }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   349
190
6dcc77582e26 made the comments in my script as rst comments
Nishanth <nishanth@fossee.in>
parents: 173
diff changeset
   350
.. #[Nishanth]: Will add this line after all of us fix on one.
191
08b2cb94c57c fixed syntax errors
Nishanth <nishanth@fossee.in>
parents: 190
diff changeset
   351
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   352
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   353
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   354
Hope you have enjoyed and found it useful.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   355
Thankyou
214
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   356
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   357
Questions
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   358
=========
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   359
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   360
 1. Draw a plot of cosine graph between -2pi to 2pi with line thickness 4
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   361
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   362
    Answer::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   363
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   364
    x = linspace(-2*pi, 2*pi)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   365
    plot(x, cos(x), linewidth=4)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   366
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   367
 2. Draw a plot of the polynomial x^2-5x+6 in the range 0 to 5 in blue dotted
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   368
    line
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   369
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   370
    Answer::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   371
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   372
    x = linspace(-2*pi, 2*pi)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   373
    plot(x, x**2 - 5*x + 6, 'r.')
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   374
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   375
 3. Which marker is used to get circles
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   376
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   377
    a. '.'
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   378
    #. '^'
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   379
    #. 'o'
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   380
    #. '--'
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   381
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   382
 4. What does the '^' marker produce
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   383
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   384
    Answer: Triangle up marker
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   385
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   386
 5. How do you set the title as x^2-5x+6 in LaTex style formatting
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   387
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   388
    Answer: title("$x^2-5x+6$")
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   389
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   390
6. What happens when the following code is executed::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   391
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   392
    xlabel("First label")
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   393
    xlabel("Second label")
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   394
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   395
   Answer: The label of x-axis is set to "Second label"
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   396
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   397
 7. Read thorugh the documentation and find out is there a way to modify the
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   398
    alignment of text in the command ``ylabel``
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   399
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   400
   a. Yes
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   401
   #. No
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   402
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   403
   Answer: No
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   404
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   405
 8. How to add the annotation "Maxima" at the point (1, 2)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   406
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   407
   Answer: annotate("Maxima", xy=(1, 2))
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   408
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   409
 9. Is the command ``annotate("max", (1, 2))`` same as ``annotate("max",
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   410
    xy=(1, 2)``
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   411
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   412
    a. True
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   413
    b. False
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   414
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   415
    Answer: True
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   416
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   417
 10. When a new annotation is made at a point, what happens to the old one
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   418
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   419
    a. It is replaced
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   420
    b. It is overwritten
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   421
    c. The new annotation is combined with old one
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   422
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   423
    Answer: It is overwritten
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   424
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   425
 11. What happens when xlim is used without arguments
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   426
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   427
    Answer: It gives the current limits of x-axis
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   428
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   429
 12. What happens when ``ylim(0, 5)`` is used
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   430
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   431
    Answer: It sets the lower and upper limits of y-axis to 0 and 5
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   432
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   433
 13. Draw a cosine plot from 0 to 2*pi with green dots. annotate the origin as
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   434
     "origin" and set x and y labels to "x" and cos(x) and x limits to 0 and
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   435
     2pi and y limits to -1.2 and 1.2
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   436
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   437
    Answer::
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   438
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   439
      x = linspace(0, 2*pi)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   440
      plot(x, cos(x), 'g.')
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   441
      annotate("origin", (0, 0))
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   442
      xlabel("$x$")
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   443
      ylabel("$cos(x)$")
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   444
      xlim(0, 2*pi)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   445
      ylim(-1.2, 1.2)
8b08fc88d5a0 Added questions
Nishanth Amuluru <nishanth@fossee.in>
parents: 193
diff changeset
   446