# HG changeset patch # User Santosh G. Vattam # Date 1269958206 -19800 # Node ID 538f59bb598ca1e5d1429d347cc8bc064f04c27f # Parent e5194abc864f32f9dc0b6979676f6637db8bcf9d Minor edits to basic-plot.txt. diff -r e5194abc864f -r 538f59bb598c basic-plot.txt --- a/basic-plot.txt Tue Mar 30 19:17:35 2010 +0530 +++ b/basic-plot.txt Tue Mar 30 19:40:06 2010 +0530 @@ -5,40 +5,38 @@ Hello, in this tutorial, we will cover the basics of the Plotting features available in Python. We shall use Ipython and pylab. Ipython is An Enhanced Interactive Python interpreter. It provides additional features like tab completion, help etc. pylab is python library which provides plotting functionality. -I am assuming that you have them installed on your system. - -Lets start IPython. Click Applications - Accessories - Terminal. The terminal window will open. Type the following command. +I am assuming that you have both of them installed on your system. $ ipython -pylab press RETURN This will give us a prompt where we can get started. -First, we create a sequence of numbers which are equally spaced starting from 0 till/to(?) 2*pi +First, we create a sequence of equally spaced points starting from 0 to 2*pi -In []: x = lins will auto complete the function. This is one of the feature of IPython. +In []: x = lins will automatically complete the function. This is one of the many useful features of IPython. In []: x = linspace(0, 2*pi, 100) -To check or read documentation on 'linspace' function type +To know more about the 'linspace' function type In []: linspace? It shows documentation related to linspace function. 'help' talks in detail about arguments to be passed, return values, some examples on usage. (To scroll down the page use 'SPACE' key and to scroll up use 'b')To navigate through content use arrow(/Page Up and Page Down) keys. ':See Also' section hints about other related or similar functions which might be useful. To exit help (mode) press 'q'. -In our case, we have passed three arguments to the linspace function - the starting point, the last point and the total number of points. +In this case, we have passed three arguments to the linspace function - the starting point, the last point and the total number of points. Check value of x by In []: x x is a sequence of 100 points starting from 0 to 2*pi. Length of x can be seen via function In []: len(x) -which shows the length of x to be 100 points. +which shows it to be 100 points. To obtain the plot we say, In []: plot(x, sin(x)) *** -As you can see a plot has come on the screen. +As you can see a plot has appeared on the screen. *** -A plot of x vs sin(x) appears on screen, with the default color and line properties. +The plot has the default color and line properties. Both 'pi' and 'sin' come from 'pylab'. @@ -60,15 +58,15 @@ 'best' 'right' -We now annotate, i.e add a comment, at the point with maximum sin value. +We now annotate, i.e add a comment, at a specific position in the graph. In this case, let's add a comment at the point with maximum sin value. In []: annotate('local max', xy=(1.5, 1)) -The first argument is the comment and second one is the position for it. +The first argument is the comment string and second one is the position for it. Now, we save the plot as follows -In []: savefig('sin.png') saves the figure as sin.png in the current directory. +In []: savefig('sin.png') saves the figure with the name 'sin.png' in the current directory. -?#other supported formats are: eps, ps, pdf etc. +#other supported formats are: eps, ps, pdf etc. When we use plot again by default plots get overlaid. In []: plot(x, cos(x)) @@ -76,23 +74,23 @@ we update Y axis label In []: ylabel('f(x)') -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. +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. -In []: legend( [ 'sin(y)' , 'cos(y)'] ) +In []: legend( [ 'sin(x)' , 'cos(x)'] ) In []: clf() -clears the plot area and start afresh. +clears the plot area and starts afresh. In case we want to create multiple plots rather than overlaid plots, we use 'figure' function. The figure command is used to open a plain figure window without any plot. In []: figure(1) plot() plot command plots a sin plot on figure(1) -In []: plot(y, sin(y)) +In []: plot(x, sin(x)) to creates a new plain figure window without any plot. In []: figure(2) -figure() also shifts the focus between multiple windows. +figure() is also used to shift the focus between multiple windows. Any command issued henceforth applies to this window only. In []: plot(x, cos(x)) @@ -120,8 +118,6 @@ Use up arrow key to get till this command In []: plot(x, cos(x), 'r') and add argument. -# For other color options you may check out 'plot?' - In []: clf() Passing the linewidth=2 option to plot, generates the plot with linewidth of two units. @@ -129,8 +125,13 @@ In []: clf() -In order to plot points in black color you can pass 'k.' parameter to plot -In []: plot(x, , 'k.') +In order to plot points you may pass '.' as a parameter to plot +In []: plot(x, sin(x), '.') + +In []: clf() + +In order to plot filled circles in black color you can pass 'ko' parameter to plot +In []: plot(x, cos(x), 'ko') In []: clf()