savefig/script.rst
changeset 290 290f3e62dc44
parent 261 c7f0069d698a
child 319 e8c02b3c51ac
equal deleted inserted replaced
289:3b801e60246a 290:290f3e62dc44
     7 
     7 
     8 =======
     8 =======
     9 Savefig
     9 Savefig
    10 =======
    10 =======
    11 
    11 
    12 Hello and welcome to the tutorial. In this tutorial you will learn how
    12 {{{ Show the first slide }}}
    13 to save plots using Python.
    13 
       
    14 Hello and welcome to the tutorial saving plots.
       
    15 
       
    16 {{{ switch to next slide, outline slide }}}
       
    17 
       
    18 In this tutorial you will learn how to save plots using Python. And
       
    19 saving in different formats, and locating the file in the file system.
       
    20 
       
    21 {{{ switch to next slide, a sine wave}}}
    14 
    22 
    15 Start your IPython interpreter with the command ::
    23 Start your IPython interpreter with the command ::
    16 
    24 
    17   ipython -pylab
    25   ipython -pylab
    18 
    26 
    36 
    44 
    37 Done! we have made a very basic sine plot, now let us see how to save
    45 Done! we have made a very basic sine plot, now let us see how to save
    38 the plot for future use so that you can embed the plot in your
    46 the plot for future use so that you can embed the plot in your
    39 reports.
    47 reports.
    40 
    48 
       
    49 {{{ switch to next slide, savefig() }}}
       
    50 
    41 {{{ Switch the focus to IPython interpreter window }}}
    51 {{{ Switch the focus to IPython interpreter window }}}
    42 
    52 
    43 For saving the plot, we will use savefig function, and it has to be
    53 For saving the plot, we will use ``savefig()`` function, and it has to be
    44 done with the plot window open. The statement is, ::
    54 done with the plot window open. The statement is, ::
    45 
    55 
    46   savefig('/home/fossee/sine.png')
    56   savefig('/home/fossee/sine.png')
    47 
    57 
    48 Notice that ``savefig`` function takes one argument which is a string
    58 Notice that ``savefig`` function takes one argument which is a string
    71 
    81 
    72 {{{ Open the file sine.png and show it for two-three seconds and then
    82 {{{ Open the file sine.png and show it for two-three seconds and then
    73 close it and return to IPython interpreter, make sure the plot window
    83 close it and return to IPython interpreter, make sure the plot window
    74 is still open, also don't close the file browser window }}}
    84 is still open, also don't close the file browser window }}}
    75 
    85 
       
    86 {{{ switch to next slide, More on savefig() }}}
       
    87 
    76 So in-order to save a plot, we use ``savefig`` function. ``savefig``
    88 So in-order to save a plot, we use ``savefig`` function. ``savefig``
    77 can save the plot in many formats, such as pdf - portable document
    89 can save the plot in many formats, such as pdf - portable document
    78 format, ps - post script, eps - encapsulated post script, svg -
    90 format, ps - post script, eps - encapsulated post script, svg -
    79 scalable vector graphics, png - portable network graphics which
    91 scalable vector graphics, png - portable network graphics which
    80 support transparency etc.
    92 support transparency etc.
    81 
    93 
    82 .. #[[slide must give the extensions for the files - Anoop]]
    94 .. #[[slide must give the extensions for the files - Anoop]]
    83 
    95 
       
    96 {{{ switch to next slide, exercise 1 }}}
       
    97 
    84 Let us now try to save the plot in eps format. ``eps`` stands for
    98 Let us now try to save the plot in eps format. ``eps`` stands for
    85 encapsulated post script, and it can be embedded in your latex
    99 encapsulated post script, and it can be embedded in your latex
    86 documents.
   100 documents. Pause here and try to figure it out yourself.
    87 
   101 
    88 {{{ Switch focus to the already open plot window }}}
   102 {{{ Switch focus to the already open plot window }}}
    89 
   103 
    90 We still have the sine plot with us, and now let us save the plot as
   104 We still have the sine plot with us, and now let us save the plot as
    91 ``sine.eps``.
   105 ``sine.eps``.
       
   106 
       
   107 {{{ switch to next slide, solution 1 }}}
    92 
   108 
    93 {{{ Switch focus to IPython interpreter }}}
   109 {{{ Switch focus to IPython interpreter }}}
    94 
   110 
    95 Now, We will save the plot using the function ``savefig`` ::
   111 Now, We will save the plot using the function ``savefig`` ::
    96 
   112 
   103 {{{ Highlight the file sine.eps with a single mouse click for 2
   119 {{{ Highlight the file sine.eps with a single mouse click for 2
   104 seconds and then double click and open the file }}}
   120 seconds and then double click and open the file }}}
   105 
   121 
   106 Yes! the new file ``sine.eps`` is here.
   122 Yes! the new file ``sine.eps`` is here.
   107 
   123 
       
   124 {{{ switch to next slide, exercise 2 }}}
       
   125 
   108 Now you may try saving the same in pdf, ps, svg formats.
   126 Now you may try saving the same in pdf, ps, svg formats.
   109 
   127 
   110 Let us review what we have learned in this session! We have learned to
   128 {{{ Switch to summary slide }}}
   111 save plots in different formats using the function ``savefig()``.
   129 
       
   130 This brings us to the end of this tutorial, in this tutorial we
       
   131 learned to save plots using the function ``savefig()``. Saving the
       
   132 plots in different formats and locating the files in the file system.
       
   133 
       
   134 {{{ switch to Thank you slide }}}
   112 
   135 
   113 Thank you!
   136 Thank you!
   114 
   137 
   115 ..  Author: Anoop Jacob Thomas <anoop@fossee.in>
   138 ..  Author: Anoop Jacob Thomas <anoop@fossee.in>
   116     Reviewer 1:
   139     Reviewer 1: