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