embellishing_a_plot.rst
changeset 214 8b08fc88d5a0
parent 193 0d175627e828
equal deleted inserted replaced
212:c3172a51b555 214:8b08fc88d5a0
       
     1 .. Author              : Nishanth
       
     2    Internal Reviewer 1 : Anoop
       
     3    Internal Reviewer 2 : Madhu
       
     4    External Reviewer   :
       
     5 
       
     6 .. Prerequisites: using ``plot`` command
       
     7 
     1 Hello friends and welcome to the tutorial on Embellishing Plots.
     8 Hello friends and welcome to the tutorial on Embellishing Plots.
     2 
     9 
     3 {{{ Show the slide containing title }}}
    10 {{{ Show the slide containing title }}}
     4 
    11 
     5 {{{ Show the slide containing the outline }}}
    12 {{{ Show the slide containing the outline }}}
     6 
    13 
     7 In this tutorial, we shall look at how to modify the colour, thickness and 
    14 In this tutorial, we shall look at how to modify the colour, thickness and 
     8 linestyle of the plot. We shall then learn how to add title to the plot and 
    15 linestyle of the plot. We shall then learn how to add title to the plot and 
     9 then look at adding labels to x and y axes. we shall also look at adding 
    16 then look at adding labels to x and y axes. we shall also look at adding 
    10 annotations to the plot.
    17 annotations to the plot and setting the limits of axes.
    11 
    18 
    12 Let us start ipython with pylab loaded, by typing on the terminal
    19 Let us start ipython with pylab loaded, by typing on the terminal
    13 
    20 
    14 {{{ shift to terminal and type ipython -pylab }}}
    21 {{{ shift to terminal and type ipython -pylab }}}
    15 
    22 
   282 
   289 
   283 {{{ continue from paused state }}}
   290 {{{ continue from paused state }}}
   284 
   291 
   285 As we can see, every annotate command makes a new annotation on the figure.
   292 As we can see, every annotate command makes a new annotation on the figure.
   286 
   293 
       
   294 Now we have everything we need to decorate a plot. but the plot would be
       
   295 incomplete if we can not set the limits of axes. This is possible using the
       
   296 button on the plot window.
       
   297 
       
   298 we shall look at how to get and set them from the script.
       
   299 ::
       
   300 
       
   301     xlim()
       
   302     ylim()
       
   303 
       
   304 We see that ``xlim`` function returns the current x axis limits and ylim
       
   305 function returns the current y-axis limits.
       
   306 
       
   307 Let us look at how to set the limits.
       
   308 ::
       
   309 
       
   310     xlim(-4, 5)
       
   311 
       
   312 We see the limits of x-axis are now set to -4 and 5.
       
   313 Similarly
       
   314 ::
       
   315 
       
   316     ylim(-15, 2)
       
   317 
       
   318 sets the limits of y-axis appropriately.
       
   319 
       
   320 {{{ Pause here and try out the following exercises }}}
       
   321 
       
   322 %% 7 %% Set the limits of axes such that the area of interest is the rectangle
       
   323         (-1, -15) and (3, 0)
       
   324 
       
   325 {{{ continue from paused state }}}
       
   326 
       
   327 As we can see, the lower upper limits of x-axis in the question are -1 and 3.
       
   328 The limits of y-axis are -15 and 0.
       
   329 
       
   330 ::
       
   331 
       
   332     xlim(-1, 3)
       
   333     ylim(-15, 0)
       
   334 
       
   335 Gives us the required rectangle.
       
   336 
   287 {{{ Show summary slide }}}
   337 {{{ Show summary slide }}}
   288 
   338 
   289 we have looked at 
   339 we have looked at 
   290 
   340 
   291  * Modifying the attributes of plot by passing additional arguments
   341  * Modifying the attributes of plot by passing additional arguments
   292  * How to add title
   342  * How to add title
   293  * How to incorporate LaTex style formatting
   343  * How to incorporate LaTex style formatting
   294  * How to label x and y axes
   344  * How to label x and y axes
   295  * How to add annotations
   345  * How to add annotations
       
   346  * How to set the limits of axes
   296 
   347 
   297 {{{ Show the "sponsored by FOSSEE" slide }}}
   348 {{{ Show the "sponsored by FOSSEE" slide }}}
   298 
   349 
   299 .. #[Nishanth]: Will add this line after all of us fix on one.
   350 .. #[Nishanth]: Will add this line after all of us fix on one.
   300 
   351 
   301 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   352 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   302 
   353 
   303 Hope you have enjoyed and found it useful.
   354 Hope you have enjoyed and found it useful.
   304 Thankyou
   355 Thankyou
   305  
   356 
   306 .. Author              : Nishanth
   357 Questions
   307    Internal Reviewer 1 : Anoop
   358 =========
   308    Internal Reviewer 2 : Madhu
   359 
   309    External Reviewer   :
   360  1. Draw a plot of cosine graph between -2pi to 2pi with line thickness 4
       
   361 
       
   362     Answer::
       
   363 
       
   364     x = linspace(-2*pi, 2*pi)
       
   365     plot(x, cos(x), linewidth=4)
       
   366 
       
   367  2. Draw a plot of the polynomial x^2-5x+6 in the range 0 to 5 in blue dotted
       
   368     line
       
   369 
       
   370     Answer::
       
   371 
       
   372     x = linspace(-2*pi, 2*pi)
       
   373     plot(x, x**2 - 5*x + 6, 'r.')
       
   374 
       
   375  3. Which marker is used to get circles
       
   376 
       
   377     a. '.'
       
   378     #. '^'
       
   379     #. 'o'
       
   380     #. '--'
       
   381 
       
   382  4. What does the '^' marker produce
       
   383 
       
   384     Answer: Triangle up marker
       
   385 
       
   386  5. How do you set the title as x^2-5x+6 in LaTex style formatting
       
   387 
       
   388     Answer: title("$x^2-5x+6$")
       
   389 
       
   390 6. What happens when the following code is executed::
       
   391 
       
   392     xlabel("First label")
       
   393     xlabel("Second label")
       
   394 
       
   395    Answer: The label of x-axis is set to "Second label"
       
   396 
       
   397  7. Read thorugh the documentation and find out is there a way to modify the
       
   398     alignment of text in the command ``ylabel``
       
   399 
       
   400    a. Yes
       
   401    #. No
       
   402 
       
   403    Answer: No
       
   404 
       
   405  8. How to add the annotation "Maxima" at the point (1, 2)
       
   406 
       
   407    Answer: annotate("Maxima", xy=(1, 2))
       
   408 
       
   409  9. Is the command ``annotate("max", (1, 2))`` same as ``annotate("max",
       
   410     xy=(1, 2)``
       
   411 
       
   412     a. True
       
   413     b. False
       
   414 
       
   415     Answer: True
       
   416 
       
   417  10. When a new annotation is made at a point, what happens to the old one
       
   418 
       
   419     a. It is replaced
       
   420     b. It is overwritten
       
   421     c. The new annotation is combined with old one
       
   422 
       
   423     Answer: It is overwritten
       
   424 
       
   425  11. What happens when xlim is used without arguments
       
   426 
       
   427     Answer: It gives the current limits of x-axis
       
   428 
       
   429  12. What happens when ``ylim(0, 5)`` is used
       
   430 
       
   431     Answer: It sets the lower and upper limits of y-axis to 0 and 5
       
   432 
       
   433  13. Draw a cosine plot from 0 to 2*pi with green dots. annotate the origin as
       
   434      "origin" and set x and y labels to "x" and cos(x) and x limits to 0 and
       
   435      2pi and y limits to -1.2 and 1.2
       
   436 
       
   437     Answer::
       
   438 
       
   439       x = linspace(0, 2*pi)
       
   440       plot(x, cos(x), 'g.')
       
   441       annotate("origin", (0, 0))
       
   442       xlabel("$x$")
       
   443       ylabel("$cos(x)$")
       
   444       xlim(0, 2*pi)
       
   445       ylim(-1.2, 1.2)
       
   446