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