embellishing_a_plot.rst
author anoop
Thu, 16 Sep 2010 15:15:01 +0530
changeset 159 8efa612b17e1
parent 138 85ed0d5d28f8
child 172 438e7bae3cf3
permissions -rw-r--r--
did internal review 1 of embellishing a plot.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
     1
Hello friends and welcome to the tutorial on Embellishing Plots
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
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
     5
{{{ Show the slide containing the outline slide }}}
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
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    12
Let us start ipython with pylab loaded, by typing
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    13
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    14
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    15
    ipython -pylab
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    16
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    17
on the terminal
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    18
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    19
{{{ shift to terminal and type ipython -pylab }}}
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    20
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    21
We shall first make a simple plot and start with decorating it.
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    22
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    23
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    24
    x = linspace(-2, 4, 20)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    25
    plot(x, sin(x))
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    26
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    27
As you can see, the colour and thickness of line as decided by pylab. It would
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    28
be nice if we could control these parameters in the plot. This is possible by
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    29
passing additional arguments to the plot command.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    30
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    31
.. #[[Anoop: I think it will be good to rephrase the sentence]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    32
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    33
The second argument that we shall be passing is colour. We shall first clear
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    34
the figure and plot the same in red colour. Hence
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
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    38
    plot(x, sin(x), 'r')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    39
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    40
Plots the same curve but now in red colour.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    41
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    42
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
    43
command. Hence
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    44
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    45
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    46
    plot(x, cos(x), linewidth=2)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    47
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    48
produces a plot with a thicker line.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    49
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    50
.. #[[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
    51
   same plot, as you have not cleared the figure]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    52
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    53
{{{ Show the plot and compare the sine and cos plots }}}
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    54
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    55
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    56
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    57
.. #[[Anoop: is the above a context switch for the person who does the
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    58
   recording, other wise if it an instruction to the person viewing the
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    59
   video, then I guess the three braces can be removed.]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    60
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    61
%% 1 %% Plot sin(x) in blue colour and with linewidth as 3
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    62
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    63
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    64
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    65
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
    66
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    67
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    68
    plot(x, sin(x), 'b', linewidth=3)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    69
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    70
.. #[[Anoop: add clf()]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    71
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    72
produces the required plot
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    73
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    74
#[Nishanth]: I could not think of a SIMPLE recipe approach for introducing
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    75
             linestyle. Hence the naive approach.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    76
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    77
.. #[[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
    78
   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
    79
   plot"]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
    80
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    81
Occasionally we would also want to alter the style of line. Sometimes all we
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    82
want is just a bunch of points not joined. This is possible by passing the
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    83
linestyle argument along with or instead of the colour argument.Hence
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    84
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    85
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    86
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    87
    plot(x, sin(x), '.')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    88
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    89
produces a plot with only points.
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
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
    92
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    93
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    94
    clf()
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    95
    plot(x, sin(x), 'b.')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    96
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
    97
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
    98
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
    99
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   100
    plot?
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   101
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   102
{{{ Run through the documentation and show the options available }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   103
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   104
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   105
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   106
.. #[[Anoop: same question as above, should it be read out?]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   107
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   108
%% 2 %% Plot the sine curve with green filled circles.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   109
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   110
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   111
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   112
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
   113
Hence
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, cos(x), 'go')
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   118
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   119
produces the required plot.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   120
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   121
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   122
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   123
%% 3 %% Produce a plot of tangent curve with red dashed line and linewidth 3
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   124
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   125
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   126
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   127
Now that we know how to produce a bare minimum plot with colour, style and
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   128
thickness of our interest, we shall look at decorating the plot.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   129
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   130
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
   131
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   132
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   133
    plot(x, -x*x + 4*x - 5, 'r', linewidth=2)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   134
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   135
{{{ Show the plot window and switch back to terminal }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   136
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   137
We now have the plot in a colour and linewidth of our interest. As you can see,
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   138
the figure does have any description describing the plot.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   139
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   140
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
   141
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   142
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   143
    title("Parabolic function -x^2+4x-5") 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   144
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   145
{{{ Show the plot window and point to the title }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   146
The figure now has a title which describes what the plot is.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   147
The =title= command as you can see, takes a string as argument and set the
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   148
title accordingly.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   149
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   150
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
   151
what would be the situation if there were fractions and more complex functions
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   152
like log and exp. Wouldn't it be good if there was LaTex like formatting.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   153
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   154
That is also possible by adding a $ sign before and after the part of the 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   155
string that should be LaTex style.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   156
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   157
for instance, we can use
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   158
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   159
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   160
    title("Parabolic function $-x^2+4x-5$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   161
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   162
and we get the polynomial formatted properly.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   163
130
5b04f1c63b16 added a comment
nishanth
parents: 129
diff changeset
   164
#[Nishanth]: Unsure if I have to give this exercise since enclosing the whole
5b04f1c63b16 added a comment
nishanth
parents: 129
diff changeset
   165
             string in LaTex style is not good
5b04f1c63b16 added a comment
nishanth
parents: 129
diff changeset
   166
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   167
.. #[[Anoop: I guess you can go ahead with the LaTex thing, it's cool!]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   168
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   169
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   170
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   171
%% 4 %% Change the title of the figure such that the whole title is formatted
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   172
        in LaTex style
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   173
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   174
{{{ continue from the paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   175
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   176
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
   177
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   178
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   179
    title("$Parabolic function -x^2+4x-5$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   180
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   181
gives a title that looks neatly formatted.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   182
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   183
Although we have title, the plot is not complete without labelling x and y
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   184
axes. Hence we shall label x-axis to "x" and y-axis to "f(x)"
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   185
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   186
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   187
    xlabel("x")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   188
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   189
{{{ Switch to plot window and show the xlabel }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   190
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   191
As you can see, =xlabel= command takes a string as argument, similar to the
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   192
=title= command and sets it to x-axis.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   193
138
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   194
Similarly,
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   195
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   196
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   197
    ylabel("f(x)")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   198
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   199
sets the name of y-axis as "f(x)"
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   200
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   201
{{{ Show the plot window and point to ylabel and switch back to terminal }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   202
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   203
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   204
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   205
%% 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
   206
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   207
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   208
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   209
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
   210
in between two $. Hence,
85ed0d5d28f8 added a newline before :: so that a colon does not appear in html
nishanth
parents: 130
diff changeset
   211
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   212
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   213
    xlabel("$x$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   214
    yalbel("$f(x)$")
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   215
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   216
does the job for us.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   217
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   218
{{{ Show the plot window with clean labels }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   219
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   220
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
   221
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
   222
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
   223
::
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   224
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   225
    annotate("local maxima", xy=(2, -1))
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   226
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   227
{{{ Show the annotation that has appeared on the plot }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   228
As you can see, the first argument to =annotate= command is the name we would
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   229
like to mark the point as and the argument after xy= is the point at which the
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   230
name should appear.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   231
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   232
.. #[[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
   233
   sequence or a tuple]]
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   234
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   235
{{{ Pause here and try out the following exercises }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   236
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   237
%% 6 %% Make an annotation called "root" at the point (-4, 0)
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   238
        What happens to the first annotation ?
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   239
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   240
{{{ continue from paused state }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   241
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   242
As we can see, every annotate command makes a new annotation on the figure.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   243
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   244
{{{ Show summary slide }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   245
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   246
we have looked at 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   247
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   248
 * Modifying the attributes of plot by passing additional arguments
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   249
 * How to add title
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   250
 * How to incorporate LaTex style formatting
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   251
 * How to label x and y axes
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   252
 * How to add annotations
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   253
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   254
{{{ Show the "sponsored by FOSSEE" slide }}}
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   255
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   256
#[Nishanth]: Will add this line after all of us fix on one.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   257
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   258
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   259
Hope you have enjoyed and found it useful.
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   260
Thankyou
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   261
 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   262
.. Author              : Nishanth
159
8efa612b17e1 did internal review 1 of embellishing a plot.
anoop
parents: 138
diff changeset
   263
   Internal Reviewer 1 : Anoop
129
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   264
   Internal Reviewer 2 : 
dcb9b50761eb initial commit of the file
nishanth
parents:
diff changeset
   265
   External Reviewer   :