basic-plot.txt
changeset 27 5712cc7589f9
parent 26 cfc86eea45b4
child 29 0278e84ec327
equal deleted inserted replaced
26:cfc86eea45b4 27:5712cc7589f9
     9 Ipython is An Enhanced Interactive Python interpreter. It provides additional features like tab completion,easier access to help , and many other useful features which are not present in the vanilla Python interpreter.
     9 Ipython is An Enhanced Interactive Python interpreter. It provides additional features like tab completion,easier access to help , and many other useful features which are not present in the vanilla Python interpreter.
    10 Pylab is python library which provides plotting functionality. 
    10 Pylab is python library which provides plotting functionality. 
    11 
    11 
    12 I am assuming that both Ipython and Pylab are installed on your system .
    12 I am assuming that both Ipython and Pylab are installed on your system .
    13 
    13 
    14 *On your terminal type in the command Ipython -pylab
    14 *On your terminal type in the command
    15 $ ipython -pylab
    15 $ ipython -pylab
    16 press RETURN
    16 press RETURN
    17 
    17 
    18 We will first start with the customary Hello world program. print hello world
    18 We will first start with the customary Hello world program by writing:
    19 
    19 
    20 In []: print 'hello world'
    20 In []: print 'hello world'
    21 
    21 
    22 Voila we have got hello world as the output 
    22 Voila we have got hello world as the output 
    23 
    23 
    36 
    36 
    37 In []  x=linspace( RETURN
    37 In []  x=linspace( RETURN
    38 oops  I made a mistake . As you can see I made the mistake of not writing command correctly
    38 oops  I made a mistake . As you can see I made the mistake of not writing command correctly
    39 and Ipython changed the prompt . To get the old prompt back type crtl-c
    39 and Ipython changed the prompt . To get the old prompt back type crtl-c
    40 
    40 
    41 In []: x = linspace(0, 2*pi, 50)
    41 In []: x = linspace(0, 2*pi, 100)
    42 
    42 
    43 *As you can see linspace can take three parameters start, stop, and num and returns num evenly space points . You can scroll through the help to know more about the function
    43 *As you can see linspace can take three parameters start, stop, and num and returns num evenly space points . You can scroll through the help to know more about the function
    44 
    44 
    45 
    45 
    46 *To know more about any function,  example for the 'linspace' function you can type ? after it .
    46 *To know more about any function,  example for the 'linspace' function you can type ? after it .
    76 
    76 
    77 Ok what if I want the legend to be in different location. It just requires us to define one extra parameter. 
    77 Ok what if I want the legend to be in different location. It just requires us to define one extra parameter. 
    78 
    78 
    79 We have just typed legend command can we reuse it . Yes 
    79 We have just typed legend command can we reuse it . Yes 
    80 
    80 
    81 To go to previous command, we can use 'UP Arrow key' and 'DOWN' will take us (in reverse order)/back.
    81 To go to previous command, we can use 'UP Arrow key' and 'DOWN' will take us back.
    82 
    82 
    83 We can modify previous command to specify the location of the legend, by passing an additional argument to the function. 
    83 We can modify previous command to specify the location of the legend, by passing an additional argument to the function. 
    84 #Ask madhu how to describe the feature here.
    84 #Ask madhu how to describe the feature here.
    85 Once you start editing a previous command and then you try to use 'Up arrow key ' you can get commands that are only similar to the command you are editing. But if you move your cursor to the beginning of the line you can get all the previous commands using up and down arrow keys.
    85 Once you start editing a previous command and then you try to use 'Up arrow key ' you can get commands that are only similar to the command you are editing. But if you move your cursor to the beginning of the line you can get all the previous commands using up and down arrow keys.
    86 In []: legend(['sin(x)'], loc = 'center')
    86 In []: legend(['sin(x)'], loc = 'center')
   100 
   100 
   101 We save the plot by the function savefig
   101 We save the plot by the function savefig
   102 In []: savefig('sin.png') saves the figure with the name 'sin.png' in the current directory. 
   102 In []: savefig('sin.png') saves the figure with the name 'sin.png' in the current directory. 
   103 
   103 
   104 #other supported formats are: eps, ps, pdf etc.
   104 #other supported formats are: eps, ps, pdf etc.
   105 When we use plot again by default plots get overlaid.
   105 When we use plot again 
   106 In []: plot(x, cos(x))
   106 In []: plot(x, cos(x)) by default plots get overlaid.
   107 
   107 
   108 we update Y axis label 
   108 we update Y axis label 
   109 In []: ylabel('f(x)')
   109 In []: ylabel('f(x)')
   110 
   110 
   111 Now in these situations with overlaid graphs, legend becomes absolutely essential. To add multiple legends, we pass the strings within quotes separated by commas and enclosed within square brackets as shown.
   111 Now in these situations with overlaid graphs, legend becomes absolutely essential. To add multiple legends, we pass the strings within quotes separated by commas and enclosed within square brackets as shown.
   145 In []: close()
   145 In []: close()
   146 
   146 
   147 close() now closes the figure(2).
   147 close() now closes the figure(2).
   148 In []: close()
   148 In []: close()
   149 
   149 
   150 The plot command can take the  parameters such as 'g' which generates the plot in green color. 
   150 The plot command can take the additional parameters such as 'g' which generates the plot in green color. 
   151 
   151 
   152 Passing the linewidth=2 option to plot, generates the plot with linewidth of two units.
   152 Passing the linewidth=2 option to plot, generates the plot with linewidth of two units.
   153 Use Up arrow to get to the previous commands 
   153 Use Up arrow to get to the previous commands 
   154 In []: plot(x, sin(x), 'g', linewidth=2) and add arguments
   154 In []: plot(x, sin(x), 'g', linewidth=2) and add arguments
   155 
   155 
   167 In []: clf()
   167 In []: clf()
   168 
   168 
   169 and finally to close the plot
   169 and finally to close the plot
   170 In []: close()
   170 In []: close()
   171 
   171 
   172 In this tutorial You learned 
   172 In this tutorial we learned 
   173 
   173 
   174 Ipython Features
   174 Some IPython Features
   175 Tab for autocompletion.
   175 Starting and exiting.
   176 function? to look at documention
   176 autocompletion.
   177 q to quit documentation.
   177 help functionality.
   178 escapping from ... prompt using Ctrl -C
       
   179 quitting ipython using Ctrl-D
       
   180 
   178 
   181 The functions and commands you learnt were :
   179 Regarding plotting we covered:
   182 print for outping things
   180 How to create basic plots.
   183 linspace to create equally space points
   181 Adding labels, legends annotation etc.
   184 plot to get a plot
   182 How to change looks of the plot like colors, linewidth formats etc
   185 xlabel to label x-axis of plot
       
   186 ylabel to label y-axis of plot
       
   187 title to title a plot
       
   188 legend for placing  appropriate legend
       
   189 annotating a plot
       
   190 saving a plot
       
   191 multiple plots using figure
       
   192 clearing plots using clf()
       
   193 and last closing plot using close()
       
   194 
       
   195 
   183 
   196 ****************
   184 ****************
   197 This brings us to the end of this tutorial. This is the first tutorial in a series of tutorials on Python for Scientific Computing. This tutorial is created by the FOSSEE team, IIT Bombay. Hope you enjoyed it and found it useful.
   185 This brings us to the end of this tutorial. This is the first tutorial in a series of tutorials on Python for Scientific Computing. This tutorial is created by the FOSSEE team, IIT Bombay. Hope you enjoyed it and found it useful.
   198 ****************
   186 ****************
   199 
   187 
   200 ************
   188 ************
   201 A slide of review of what has been covered and sequentially/rapidly going through them.
   189 A slide of review of what has been covered and sequentially/rapidly going through them.
   202 ************
   190 ************
   203 
   191 
   204 Various problems of Ipython, navigation and enter, exit.
   192 Various problems of Ipython, navigation and enter, exit.
       
   193 What about xlim and ylim?