embellishing_a_plot.rst
changeset 162 4a3181371fd3
parent 159 8efa612b17e1
child 172 438e7bae3cf3
equal deleted inserted replaced
161:b7c47307e510 162:4a3181371fd3
    14 
    14 
    15     ipython -pylab
    15     ipython -pylab
    16 
    16 
    17 on the terminal
    17 on the terminal
    18 
    18 
    19 {{{ shit to terminal and type ipython -pylab }}}
    19 {{{ shift to terminal and type ipython -pylab }}}
    20 
    20 
    21 We shall first make a simple plot and start with decorating it.
    21 We shall first make a simple plot and start with decorating it.
    22 ::
    22 ::
    23 
    23 
    24     x = linspace(-2, 4, 20)
    24     x = linspace(-2, 4, 20)
    26 
    26 
    27 As you can see, the colour and thickness of line as decided by pylab. It would
    27 As you can see, the colour and thickness of line as decided by pylab. It would
    28 be nice if we could control these parameters in the plot. This is possible by
    28 be nice if we could control these parameters in the plot. This is possible by
    29 passing additional arguments to the plot command.
    29 passing additional arguments to the plot command.
    30 
    30 
       
    31 .. #[[Anoop: I think it will be good to rephrase the sentence]]
       
    32 
    31 The second argument that we shall be passing is colour. We shall first clear
    33 The second argument that we shall be passing is colour. We shall first clear
    32 the figure and plot the same in red colour.Hence
    34 the figure and plot the same in red colour. Hence
    33 ::
    35 ::
    34 
    36 
    35     clf()
    37     clf()
    36     plot(x, sin(x), 'r')
    38     plot(x, sin(x), 'r')
    37 
    39 
    38 Plots the same curve but now in red colour.
    40 Plots the same curve but now in red colour.
    39 
    41 
    40 To alter the thickness of the line, we use the =linewidth= argument in the plot
    42 To alter the thickness of the line, we use the =linewidth= argument in the plot
    41 command.Hence
    43 command. Hence
    42 ::
    44 ::
    43 
    45 
    44     plot(x, cos(x), linewidth=2)
    46     plot(x, cos(x), linewidth=2)
    45 
    47 
    46 produces a plot with a thicker line.
    48 produces a plot with a thicker line.
    47 
    49 
    48 {{{ Show the plot and compare the sin and cos plots }}}
    50 .. #[[Anoop: I guess it will be good if you say that it affects the
    49 
    51    same plot, as you have not cleared the figure]]
    50 {{{ Pause here and try out the following exercises }}}
    52 
       
    53 {{{ Show the plot and compare the sine and cos plots }}}
       
    54 
       
    55 {{{ Pause here and try out the following exercises }}}
       
    56 
       
    57 .. #[[Anoop: is the above a context switch for the person who does the
       
    58    recording, other wise if it an instruction to the person viewing the
       
    59    video, then I guess the three braces can be removed.]]
    51 
    60 
    52 %% 1 %% Plot sin(x) in blue colour and with linewidth as 3
    61 %% 1 %% Plot sin(x) in blue colour and with linewidth as 3
    53 
    62 
    54 {{{ continue from paused state }}}
    63 {{{ continue from paused state }}}
    55 
    64 
    56 A combination of colour and linewidth would do the job for us. Hence
    65 A combination of colour and linewidth would do the job for us. Hence
    57 ::
    66 ::
    58 
    67 
    59     plot(x, sin(x), 'b', linewidth=3)
    68     plot(x, sin(x), 'b', linewidth=3)
       
    69 
       
    70 .. #[[Anoop: add clf()]]
    60 
    71 
    61 produces the required plot
    72 produces the required plot
    62 
    73 
    63 #[Nishanth]: I could not think of a SIMPLE recipe approach for introducing
    74 #[Nishanth]: I could not think of a SIMPLE recipe approach for introducing
    64              linestyle. Hence the naive approach.
    75              linestyle. Hence the naive approach.
       
    76 
       
    77 .. #[[Anoop: I guess the recipe is fine, but would be better if you
       
    78    add the problem statement rather than just saying "let's do a simple
       
    79    plot"]]
    65 
    80 
    66 Occasionally we would also want to alter the style of line. Sometimes all we
    81 Occasionally we would also want to alter the style of line. Sometimes all we
    67 want is just a bunch of points not joined. This is possible by passing the
    82 want is just a bunch of points not joined. This is possible by passing the
    68 linestyle argument along with or instead of the colour argument.Hence
    83 linestyle argument along with or instead of the colour argument.Hence
    69 ::
    84 ::
    85     plot?
   100     plot?
    86 
   101 
    87 {{{ Run through the documentation and show the options available }}}
   102 {{{ Run through the documentation and show the options available }}}
    88 
   103 
    89 {{{ Pause here and try out the following exercises }}}
   104 {{{ Pause here and try out the following exercises }}}
       
   105 
       
   106 .. #[[Anoop: same question as above, should it be read out?]]
    90 
   107 
    91 %% 2 %% Plot the sine curve with green filled circles.
   108 %% 2 %% Plot the sine curve with green filled circles.
    92 
   109 
    93 {{{ continue from paused state }}}
   110 {{{ continue from paused state }}}
    94 
   111 
   145 and we get the polynomial formatted properly.
   162 and we get the polynomial formatted properly.
   146 
   163 
   147 #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole
   164 #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole
   148              string in LaTex style is not good
   165              string in LaTex style is not good
   149 
   166 
       
   167 .. #[[Anoop: I guess you can go ahead with the LaTex thing, it's cool!]]
       
   168 
   150 {{{ Pause here and try out the following exercises }}}
   169 {{{ Pause here and try out the following exercises }}}
   151 
   170 
   152 %% 4 %% Change the title of the figure such that the whole title is formatted
   171 %% 4 %% Change the title of the figure such that the whole title is formatted
   153         in LaTex style
   172         in LaTex style
   154 
   173 
   207 
   226 
   208 {{{ Show the annotation that has appeared on the plot }}}
   227 {{{ Show the annotation that has appeared on the plot }}}
   209 As you can see, the first argument to =annotate= command is the name we would
   228 As you can see, the first argument to =annotate= command is the name we would
   210 like to mark the point as and the argument after xy= is the point at which the
   229 like to mark the point as and the argument after xy= is the point at which the
   211 name should appear.
   230 name should appear.
       
   231 
       
   232 .. #[[Anoop: I think we should tell explicitely that xy takes a
       
   233    sequence or a tuple]]
   212 
   234 
   213 {{{ Pause here and try out the following exercises }}}
   235 {{{ Pause here and try out the following exercises }}}
   214 
   236 
   215 %% 6 %% Make an annotation called "root" at the point (-4, 0)
   237 %% 6 %% Make an annotation called "root" at the point (-4, 0)
   216         What happens to the first annotation ?
   238         What happens to the first annotation ?
   236 
   258 
   237 Hope you have enjoyed and found it useful.
   259 Hope you have enjoyed and found it useful.
   238 Thankyou
   260 Thankyou
   239  
   261  
   240 .. Author              : Nishanth
   262 .. Author              : Nishanth
   241    Internal Reviewer 1 : 
   263    Internal Reviewer 1 : Anoop
   242    Internal Reviewer 2 : 
   264    Internal Reviewer 2 : 
   243    External Reviewer   :
   265    External Reviewer   :