19 External Reviewer : |
19 External Reviewer : |
20 Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
20 Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
21 |
21 |
22 Script |
22 Script |
23 ------- |
23 ------- |
24 |
24 {{{ Show the Title Slide }}} |
25 |
25 |
26 Hello and welcome to the tutorial on creating simple plots using |
26 Hello and welcome to the tutorial on creating simple plots using |
27 Python.This tutorial is presented by the Fossee group. |
27 Python.This tutorial is presented by the Fossee group. |
28 {{{ Show the Title Slide }}} |
|
29 |
28 |
30 I hope you have IPython running on your computer. |
29 I hope you have IPython running on your computer. |
31 |
30 |
32 In this tutorial we will look at plot command and also how to study |
31 In this tutorial we will look at plot command and also how to study |
33 the plot using the UI. |
32 the plot using the UI. |
50 |
49 |
51 |
50 |
52 {{{ Slide with Error written on it }}} |
51 {{{ Slide with Error written on it }}} |
53 |
52 |
54 |
53 |
55 |
|
56 |
|
57 Then you have to install matplotlib and run this command again. |
54 Then you have to install matplotlib and run this command again. |
58 |
55 |
59 Now type in your ipython shell :: |
56 Now type in your ipython shell :: |
60 |
57 |
61 In[]: linpace? |
58 linpace? |
62 |
59 |
63 |
60 |
64 |
61 |
65 as the documentation says, it returns `num` evenly spaced samples, |
62 as the documentation says, it returns `num` evenly spaced samples, |
66 calculated over the interval start and stop. To illustrate this, lets |
63 calculated over the interval start and stop. To illustrate this, lets |
67 do it form 1 to 100 and try 100 points. :: |
64 do it form 1 to 100 and try 100 points. :: |
68 |
65 |
69 In[]: linspace(1,100,100) |
66 linspace(1,100,100) |
70 |
67 |
71 As you can see a sequence of numbers from 1 to 100 appears. |
68 As you can see a sequence of numbers from 1 to 100 appears. |
72 |
69 |
73 Now lets try 200 points between 0 and 1 you do this by typing :: |
70 Now lets try 200 points between 0 and 1 you do this by typing :: |
74 |
71 |
75 |
72 |
76 In[]: linspace(0,1,200) |
73 linspace(0,1,200) |
77 |
74 |
78 0 for start , 1 for stop and 200 for no of points. In linspace |
75 0 for start , 1 for stop and 200 for no of points. In linspace |
79 the start and stop points can be integers, decimals , or |
76 the start and stop points can be integers, decimals , or |
80 constants. Let's try and get 100 points between -pi to pi. Type :: |
77 constants. Let's try and get 100 points between -pi to pi. Type :: |
81 |
78 |
82 In[]: p = linspace(-pi,pi,100) |
79 p = linspace(-pi,pi,100) |
83 |
80 |
84 |
81 |
85 'pi' here is constant defined by pylab. Save this to the variable, p |
82 'pi' here is constant defined by pylab. Save this to the variable, p |
86 . |
83 . |
87 |
84 |
88 If you now :: |
85 If you now :: |
89 |
86 |
90 In[]: len(p) |
87 len(p) |
91 |
88 |
92 You will get the no. of points. len function gives the no of elements |
89 You will get the no. of points. len function gives the no of elements |
93 of a sequence. |
90 of a sequence. |
94 |
91 |
95 |
92 |
96 Let's try and plot a cosine curve between -pi and pi using these |
93 Let's try and plot a cosine curve between -pi and pi using these |
97 points. Simply type :: |
94 points. Simply type:: |
98 |
95 |
99 |
96 plot(p,cos(points)) |
100 In[]: plot(p,cos(points)) |
97 |
101 |
98 |
102 Here cos(points) gets the cosine value at every corresponding point to |
99 Here cos(points) gets the cosine value at every corresponding point to |
103 p. |
100 p. |
104 |
101 |
105 |
102 |
106 We can also save cos(points) to variable cosine and plot it using |
103 We can also save cos(points) to variable cosine and plot it using |
107 plot.:: |
104 plot.:: |
108 |
105 |
109 In[]: cosine=cos(points) |
106 cosine=cos(points) |
110 |
107 |
111 In[]: plot(p,cosine) |
108 plot(p,cosine) |
112 |
109 |
113 |
110 |
114 |
111 |
115 Now do :: |
112 Now do :: |
116 |
113 |
117 In[]: clf() |
114 clf() |
118 |
115 |
119 this will clear the plot. |
116 this will clear the plot. |
120 |
117 |
121 This is done because any other plot we try to make shall come on the |
118 This is done because any other plot we try to make shall come on the |
122 same drawing area. As we do not wish to clutter the area with |
119 same drawing area. As we do not wish to clutter the area with |
123 overlaid plots , we just clear it with clf(). Now lets try a sine |
120 overlaid plots , we just clear it with clf(). Now lets try a sine |
124 plot. :: |
121 plot. :: |
125 |
122 |
126 |
123 |
127 In []: plot(p,sin(p)) |
124 plot(p,sin(p)) |
128 |
125 |
129 |
126 |
130 |
127 |
131 |
128 |
132 The Window on which the plot appears can be used to study it better. |
129 The Window on which the plot appears can be used to study it better. |
142 Just click on it specifying the name of the file. We will save the plot |
139 Just click on it specifying the name of the file. We will save the plot |
143 by the name sin_curve in pdf format. |
140 by the name sin_curve in pdf format. |
144 |
141 |
145 |
142 |
146 |
143 |
147 {{{ Action corelating with the words }}} |
144 {{{ Show how to save the file }}} |
148 |
145 |
149 As you can see I can specify format of file from the dropdown. |
146 As you can see I can specify format of file from the dropdown. |
150 |
147 |
151 Formats like png ,eps ,pdf, ps are available. |
148 Formats like png ,eps ,pdf, ps are available. |
152 |
149 |
153 Left to the save button is the slider button to specify the margins. |
150 Left to the save button is the slider button to specify the margins. |
154 |
151 |
155 {{{ Action corelating with the words }}} |
152 {{{ Show how to zoom. Press zoom button and specify region to zoom }}} |
156 |
153 |
157 Left to this is zoom button to zoom into the plot. Just specify the |
154 Left to this is zoom button to zoom into the plot. Just specify the |
158 region to zoom into. |
155 region to zoom into. |
|
156 |
|
157 {{{ Press Move button and move the axes. }}} |
|
158 |
159 The button left to it can be used to move the axes of the plot. |
159 The button left to it can be used to move the axes of the plot. |
160 |
160 |
161 {{{ Action corelating with the words }}} |
161 {{{ Press Back and Forward Button }}} |
162 |
162 |
163 The next two buttons with a left and right arrow icons change the state of the |
163 The next two buttons with a left and right arrow icons change the state of the |
164 plot and take it to the previous state it was in. It more or less acts like a |
164 plot and take it to the previous state it was in. It more or less acts like a |
165 back and forward button in the browser. |
165 back and forward button in the browser. |
166 |
166 |
167 {{{ Action corelating with the words }}} |
167 {{{ Press home button }}} |
168 |
168 |
169 The last one is 'home' referring to the initial plot. |
169 The last one is 'home' referring to the initial plot. |
170 |
170 |
171 {{{ Action corelating with the words}}} |
171 |
|
172 |
|
173 |
|
174 Following is an exercise that you must do. |
|
175 |
|
176 %% %% Plot (sin(x)*sin(x))/x . |
|
177 1. Save the plot by the sinsquarebyx.pdf in pdf format. |
|
178 2. Zoom and find the maxima. |
|
179 |
|
180 3. Bring it back to initial position. |
|
181 |
|
182 |
|
183 Please, pause the video here. Do the exercise and then continue. |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
172 |
190 |
173 |
191 |
174 |
192 |
175 {{{ Summary Slide }}} |
193 {{{ Summary Slide }}} |
176 |
194 |
177 |
|
178 In this tutorial we have looked at |
195 In this tutorial we have looked at |
179 |
196 |
180 1. Starting Ipython with pylab |
197 1. Starting Ipython with pylab |
181 |
198 |
182 2. Using linspace function to create `num` equaly spaced points in a region. |
199 2. Using linspace function to create `num` equaly spaced points in a region. |