embellishing_a_plot/script.rst
author Nishanth <nishanth@fossee.in>
Sun, 10 Oct 2010 15:49:44 +0530
changeset 293 ca701f1ef7fb
parent 235 80e4016d747a
child 273 1639ef25a231
permissions -rw-r--r--
reviewed questions
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     9
.. Prerequisites
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    10
.. -------------
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    11
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    12
..   1. Using the ``plot`` command interactively
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    13
     
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    14
.. Author              : Nishanth Amuluru
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    15
   Internal Reviewer   : 
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    16
   External Reviewer   :
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    17
   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
    18
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    19
Script
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    22
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
    23
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    24
{{{ Show the slide containing title }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    25
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    26
{{{ Show the slide containing the outline }}}
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
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
    29
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
    30
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
    31
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
    32
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    33
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
    34
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    35
{{{ shift to terminal and type ipython -pylab }}}
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
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    38
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    39
    ipython -pylab
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    40
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    41
.. #[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
    42
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    43
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
    44
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    45
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
    46
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    47
.. #[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
    48
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    51
    x = linspace(-2, 4, 20)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    52
    plot(x, sin(x))
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
.. #[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
    55
     points right?]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    56
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    57
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
    58
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
    59
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
    60
arguments to the plot command.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    61
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    62
.. #[[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
    63
.. #[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
    64
     added "the default" check the diff]
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
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
    67
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
    68
red colour. Hence
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    69
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    70
.. #[Madhu: Note the diff for changes]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    71
 ::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    72
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    73
    clf()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    74
    plot(x, sin(x), 'r')
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    75
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    76
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
    77
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    78
.. #[Madhu: diff again]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    79
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    80
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
    81
command. Hence
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    82
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    83
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    84
    plot(x, cos(x), linewidth=2)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    85
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    86
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
    87
thickness 2.
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
.. #[[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
    90
   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
    91
.. #[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
    92
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    93
{{{ 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
    94
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    95
{{{ 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
    96
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    97
.. #[[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
    98
   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
    99
   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
   100
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   101
%% 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
   102
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   103
{{{ continue from paused state }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   104
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   105
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
   106
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   107
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   108
    clf()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   109
    plot(x, sin(x), 'b', linewidth=3)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   110
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   111
.. #[[Anoop: add clf()]]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   112
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   113
produces the required plot
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   114
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   115
.. #[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
   116
             introducing linestyle. Hence the naive approach.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   117
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   118
.. #[[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
   119
   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
   120
   plot"]]
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
.. #[Madhu: It is good enough.]
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
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
   125
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
   126
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
   127
argument. Hence ::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   128
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   129
    clf()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   130
    plot(x, sin(x), '.')
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   131
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   132
produces a plot with only points.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   133
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   134
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
   135
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   136
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   137
    clf()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   138
    plot(x, sin(x), 'b.')
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   139
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   140
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
   141
::
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
    plot?
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
{{{ 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
   146
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   147
{{{ 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
   148
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   149
.. #[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
   150
     explained.]
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
{{{ 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
   153
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   154
.. #[[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
   155
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   156
%% 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
   157
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   158
{{{ continue from paused state }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   159
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   160
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
   161
Hence
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   164
    clf()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   165
    plot(x, cos(x), 'go')
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
produces the required plot.
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
{{{ 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
   170
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   171
%% 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
   172
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   173
{{{ continue from paused state }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   174
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   175
.. #[Madhu: I did not understand the question]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   176
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   177
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
   178
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
   179
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   180
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
   181
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   182
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   183
    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
   184
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   185
{{{ 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
   186
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   187
We now have the plot in a colour and linewidth of our interest. As you can see,
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   188
the figure does not have any description describing the plot.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   189
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   190
.. #[Madhu: Added "not". See the diff]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   191
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   192
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
   193
::
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
    title("Parabolic function -x^2+4x-5") 
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   196
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   197
{{{ 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
   198
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   199
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
   200
``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
   201
the title accordingly.
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: 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
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
   206
what would be the situation if there were fractions and more complex functions
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   207
like log and exp. Wouldn't it be good if there was LaTex like formatting?
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   208
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   209
That is also possible by adding a $ sign before and after the part of the 
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   210
string that should be in LaTex style.
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
for instance, we can use
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   213
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   214
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   215
    title("Parabolic function $-x^2+4x-5$")
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   216
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   217
and we get the polynomial formatted properly.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   218
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   219
.. #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   220
             string in LaTex style is not good
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
.. #[[Anoop: I guess you can go ahead with the LaTex thing, it's
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   223
     cool!]]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   224
.. #[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
   225
     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
   226
     doesn't really solve the purpose]
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
{{{ 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
   229
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   230
%% 4 %% Change the title of the figure such that the whole title is formatted
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   231
        in LaTex style
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   232
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   233
{{{ continue from the paused state }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   234
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   235
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
   236
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   237
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   238
    title("$Parabolic function -x^2+4x-5$")
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   239
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   240
gives a title that looks neatly formatted.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   241
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   242
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
   243
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
   244
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   245
    xlabel("x")
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   246
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   247
{{{ 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
   248
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   249
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
   250
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
   251
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   252
.. #[See the diff]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   253
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   254
Similarly,
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   255
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   256
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   257
    ylabel("f(x)")
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   258
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   259
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
   260
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   261
{{{ 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
   262
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   263
{{{ 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
   264
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   265
%% 5 %% Set the x and y labels as "x" and "f(x)" in LaTex style.
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
{{{ continue from paused state }}}
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
Since we need LaTex style formatting, all we have to do is enclose the string
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   270
in between two $. Hence,
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   273
    xlabel("$x$")
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   274
    yalbel("$f(x)$")
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
does the job for us.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   277
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   278
{{{ Show the plot window with clean labels }}}
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
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
   281
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
   282
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
   283
::
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
    annotate("local maxima", xy=(2, -1))
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   286
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   287
{{{ 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
   288
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   289
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
   290
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
   291
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
   292
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
   293
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   294
.. #[[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
   295
   sequence or a tuple]]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   296
.. #[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
   297
     part should be rephrased I think.]
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   298
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   299
{{{ 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
   300
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   301
%% 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
   302
        What happens to the first annotation ?
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   303
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   304
{{{ continue from paused state }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   305
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   306
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
   307
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   308
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
   309
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
   310
button on the plot window.
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
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
   313
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   314
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   315
    xlim()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   316
    ylim()
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   317
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   318
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
   319
function returns the current y-axis limits.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   320
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   321
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
   322
::
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   323
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   324
    xlim(-4, 5)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   325
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   326
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
   327
Similarly
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
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   330
    ylim(-15, 2)
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
sets the limits of y-axis appropriately.
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   333
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   334
{{{ 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
   335
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   336
%% 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
   337
        (-1, -15) and (3, 0)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   338
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   339
{{{ continue from paused state }}}
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
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
   342
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
   343
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   344
::
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
    xlim(-1, 3)
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   347
    ylim(-15, 0)
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
Gives us the required rectangle.
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
{{{ Show summary slide }}}
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
we have looked at 
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   354
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   355
 * 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
   356
 * How to add title
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   357
 * How to incorporate LaTex style formatting
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   358
 * How to label x and y axes
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   359
 * How to add annotations
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   360
 * How to set the limits of axes
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
{{{ Show the "sponsored by FOSSEE" slide }}}
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   363
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   364
.. #[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
   365
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   366
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
   367
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   368
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
   369
Thankyou
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   370
80e4016d747a Converted the embellishing_a_plot to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
   371