multiple-plots.rst
author Nishanth <nishanth@fossee.in>
Thu, 23 Sep 2010 11:00:44 +0530
changeset 191 08b2cb94c57c
parent 184 a005328abdf0
child 207 2f30ecfd6007
permissions -rw-r--r--
fixed syntax errors
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
Hello friends. Welcome to this spoken tutorial on Multiple plots.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
{{{ Show the slide containing the title }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
{{{ Show the slide containing the outline }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
In this tutorial, we will learn how to draw more than one plot, how to
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
add legends to each plot to indicate what each plot represents. We
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
     9
will also learn how to switch between the plots and create multiple
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
plots with different regular axes which are also called as subplots.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    12
.. #[Nishanth]: See diff - edited a grammatical mistake
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    13
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
{{{ Shift to terminal and start ipython -pylab }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
To begin with let us start ipython with pylab, by typing::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
  ipython -pylab
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
on the terminal
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
Let us first create set of points for our plot. For this we will use
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
the command called linspace::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
  x = linspace(0, 50, 10)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
linspace command creates 10 points in the interval between 0 and 50
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
both inclusive. We assign these values to a variable called x.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    30
.. #[Nishanth]: pre requisite for this LO is basic plotting which
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    31
                covers linspace and plot. So you may not need to 
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    32
                specify all that again. But not a problem if it is
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    33
                there also.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    34
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
Now let us draw a plot simple sine plot using these points::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
  plot(x, sin(x))
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
This should give us a nice sine plot.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
{{{ Switch to the plot window }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
Oh! wait! Is that a nice sine plot? Does a sine plot actually look
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    44
like that? We know that a sine plot is a smooth curve. Is it not? What
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
really caused this?
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    47
.. #[Nishanth]: See diff
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    48
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
{{{ pause for a while }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
A small investigation on linspace tells us that we chose too few
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
points in a large interval between 0 and 50 for the curve to be
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
smooth. So now let us use linspace again to get 500 points between 0
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
and 100 and draw the sine plot
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    56
.. #[Nishanth]: Here specify that when we do plot(x, sin(x) 
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    57
                it is actually plotting two sets of points
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    58
                and not analytical functions. Hence the sharp 
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    59
                curve.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    60
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
{{{ Switch to ipython andtype }}} ::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
  y = linspace(0, 50, 500)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
  plot(y, sin(y))
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
{{{ Change to the plot window }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
Now we see what we remember as a sine plot. A smooth curve. If we
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
carefully notice we also have two plots now one overlaid upon
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
another. In pylab, by default all the plots are overlaid.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
We now know how to draw multiple plots but we would like to have more
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
control over it. Like switch between them, perform some operations or
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
labelling on them individually and so on. Let us see how to accomplish
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
this. Before we move on, let us clear our screen.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
  clf()
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
To accomplishing more control over individual plots we use the figure
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
command::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
  x = linspace(0, 50, 500)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
  figure(1)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
  plot(x, sin(x), 'b')
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
  figure(2)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
  plot(x, cos(x), 'g')
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
{{{ Switch to plot window }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
Now we have two plots, a sine plot and a cosine plot one overlaid upon
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
the other.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    95
.. #[Nishanth]: figure(1) and figure(2) give two different plots.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    96
                The remaining script moves on the fact that they 
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    97
                give overlaid plots which is not the case.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    98
                So clear the figure and plot cos and sin without
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
    99
                introducing figure command. Then introduce legend
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   100
                and finish off the everything on legend.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   101
                Then introduce figure command.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   102
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
{{{ Have both plot window and ipython side by side }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
The figure command takes an integer as an argument which is the serial
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
number of the plot. This selects the corresponding plot. All the plot
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
commands we run after this are applied to the selected plot. In this
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
example figure 1 is the sine plot and figure 2 is the cosine plot. We
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
can, for example, save each plot separately
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
  savefig('/home/user/cosine.png')
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
  figure(1)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
  title('sin(y)')
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
  savefig('/home/user/sine.png')
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
{{{ Have both plot window and ipython side by side }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
We also titled the our first plot as 'sin(y)' which we did not do for
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
the second plot.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
Since we have two plots now overlaid upon each other we would like to
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
have a way to indicate what each plot represents to distinguish
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
between them. This is accomplished using legends. Equivalently, the
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
legend command does this for us
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
  legend(['sin(x)', 'cos(x)'])
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   132
.. #[Nishanth]: This legend may go up in the script. May be before 
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   133
                introducing the figure command itself.
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   134
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
The legend command takes a single list of parameters where each
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
parameter is the text indicating the plots in the order of their
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
serial number.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
{{{ Switch to plot window }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
Now we can see the legends being displayed for the respective sine and
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
cosine plots on the plot area.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
At times we run into situations where we want to compare two plots and
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
in such cases we want to draw both the plots in the same plotting
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
area. The situation is such that the two plots have different regular
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
axes which means we cannot draw overlaid plots. In such cases we can
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
draw subplots.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
We use subplot command to accomplish this
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
  subplot(2, 1, 1)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
subplot command takes three arguments, the first being the number of
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
rows of subplots that must be created,
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
{{{ Have both plot window and ipython side by side }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
in this case we have 2 so it spilts the plotting area horizontally for
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
two subplots. The second argument specifies the number of coloumns of
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
subplots that must be created. We passed 1 as the argument so the
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
plotting area won't be split horizontally and the last argument
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
specifies what subplot must be created now in the order of the serial
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
number. In this case we passed 1 as the argument, so the first subplot
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
that is top half is created. If we execute the subplot command as
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
  subplot(2, 1, 2)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
{{{ Switch to plot window }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
The lower subplot is created. Now we can draw plots in each of the
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
subplot area using the plot command.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
{{{ Switch to ipython }}}::
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
  x = linspace(0, 50, 500)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
  plot(x, cos(x))
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
  subplot(2, 1, 1)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
  y = linspace(0, 5, 100)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
  plot(y, y ** 2)
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
{{{ Have both plot window and ipython side by side }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
This created two plots one in each of the subplot area. The top
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
subplot holds a parabola and the bottom subplot holds a cosine
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
curve.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
As seen here we can use subplot command to switch between the subplot
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
as well, but we have to use the same arguments as we used to create
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
that subplot, otherwise the previous subplot at that place will be
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
automatically erased. It is clear from the two subplots that both have
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
different regular axes. For the cosine plot x-axis varies from 0 to
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
100 and y-axis varies from 0 to 1 where as for the parabolic plot the
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
x-axis varies from 0 to 10 and y-axis varies from 0 to 100
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   200
.. #[Nishanth]: stress on the similarity between subplot and figure commands
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   201
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
{{{ Show summary slide }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   204
.. #[Nishanth]: Exercises are missing in the script
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   205
                one exercise for overlaid plot and legend
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   206
                one for figure command
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   207
                one for subplot must do
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   208
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
This brings us to the end of another session. In this tutorial session
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
we learnt
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
 * How to draw multiple plots which are overlaid
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
 * the figure command
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
 * how to switch between the plots and perform some operations on each
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
   of them like saving the plots
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
 * the legend command and
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
 * creating and switching between subplots
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   219
.. #[Nishanth]: legend command can be told right after overlaid plots
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   220
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
{{{ Show the "sponsored by FOSSEE" slide }}}
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
Hope you have enjoyed and found it useful.
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
Thankyou
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
 
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
.. Author              : Madhu
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
   Internal Reviewer 1 :         [potential reviewer: Puneeth]
184
a005328abdf0 Reviewed multiple_plots
Nishanth <nishanth@fossee.in>
parents: 165
diff changeset
   230
   Internal Reviewer 2 : Nishanth
165
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
   External Reviewer   :
53df732199a1 Completed multiple plots script and for review with reviewers names.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232