Difference between revisions of "Python-3.4.3/C2/Using-plot-command-interactively/English-timed"
(Created page with "{|border=1 | Time | Narration |- | 00:01 | Hello friends. Welcome to the tutorial on using '''plot '''command interactively in '''IPython''' |- | 00:08 |At the end of this...") |
Sandhya.np14 (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{|border=1 | {|border=1 | ||
− | | Time | + | | '''Time''' |
− | | Narration | + | | '''Narration''' |
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Hello friends | + | | Hello friends! Welcome to the tutorial on using '''plot '''command interactively in '''IPython'''. |
|- | |- | ||
| 00:08 | | 00:08 | ||
− | |At the end of this tutorial, you will be able to | + | |At the end of this tutorial, you will be able to: |
− | + | create simple '''plots''' of mathematical '''functions''', | |
− | + | use the '''Plot window''' to study '''plots '''better. | |
|- | |- | ||
| 00:20 | | 00:20 | ||
− | | To record this tutorial, I am using | + | | To record this tutorial, I am using: |
− | '''Ubuntu Linux 14.04''' operating system | + | '''Ubuntu Linux 14.04''' operating system, |
− | '''Python 3.4.3''' | + | '''Python 3.4.3''' and |
'''IPython 5.1.0''' | '''IPython 5.1.0''' | ||
Line 29: | Line 29: | ||
|Pre-requisites to practise this tutorial are - | |Pre-requisites to practise this tutorial are - | ||
− | + | you should know how to '''run''' basic '''Python '''commands on the '''ipython console.''' | |
|- | |- | ||
Line 45: | Line 45: | ||
|- | |- | ||
| 01:05 | | 01:05 | ||
− | | Let us initialise the '''pylab package'''. Type | + | | Let us initialise the '''pylab package'''. Type: percentage '''pylab '''and press''' Enter'''. |
|- | |- | ||
| 01:16 | | 01:16 | ||
− | | Let's first understand what is '''Pylab''' | + | | Let's first understand what is '''Pylab'''. |
|- | |- | ||
| 01:20 | | 01:20 | ||
− | |'''Pylab''' is a convenient '''Python''' '''module''' | + | |'''Pylab''' is a convenient '''Python''' '''module''' |
− | + | which provides- | |
− | which provides '''plotting''' functionality and has | + | '''plotting''' functionality and |
+ | has mathematical and scientific '''functions'''. | ||
|- | |- | ||
| 01:32 | | 01:32 | ||
− | | After running '''percentage pylab '''in the | + | | After running '''percentage pylab '''in the '''iPython console''', you will see a message- |
“'''Using matplotlib backend: TkAgg ”.''' | “'''Using matplotlib backend: TkAgg ”.''' | ||
Line 69: | Line 70: | ||
|- | |- | ||
|01:45 | |01:45 | ||
− | | But sometimes you may get an error that says | + | | But sometimes you may get an error that says- |
'''“ImportError: No module named matplotlib”.''' | '''“ImportError: No module named matplotlib”.''' | ||
|- | |- | ||
|01:55 | |01:55 | ||
− | | In such cases, you have to install '''matplotlib''' and run this '''command''' again. | + | | In such cases, you have to install '''matplotlib''' and '''run''' this '''command''' again. |
|- | |- | ||
|02:02 | |02:02 | ||
− | | Let's come back to the '''ipython console'''. Type ''''linspace'''' followed by a question mark in '''ipython console. ''' Press '''Enter''' | + | | Let's come back to the '''ipython console'''. Type ''''linspace'''' followed by a question mark in '''ipython console. ''' Press '''Enter'''. |
|- | |- | ||
|02:14 | |02:14 | ||
− | | Please note that the '''command '''is''' linspace '''and | + | | Please note that the '''command '''is''' linspace '''and not''' linespace.''' |
|- | |- | ||
Line 88: | Line 89: | ||
| The displayed information says that | | The displayed information says that | ||
− | '''linspace''' returns evenly spaced | + | '''linspace''' returns evenly spaced numbers |
which are calculated over the interval '''start''' and '''stop'''. | which are calculated over the interval '''start''' and '''stop'''. | ||
Line 97: | Line 98: | ||
|- | |- | ||
|02:41 | |02:41 | ||
− | | Let's try to generate 100 points from 1 to 100. Type '''linspace brackets 1 comma 100 comma 100''' | + | | Let's try to generate 100 points from 1 to 100. Type: '''linspace brackets 1 comma 100 comma 100''' |
|- | |- | ||
Line 113: | Line 114: | ||
|- | |- | ||
|03:21 | |03:21 | ||
− | | We do that by typing '''linspace brackets 0 comma 1 comma 200 '''and press | + | | We do that by typing '''linspace brackets 0 comma 1 comma 200 '''and press '''Enter'''. |
|- | |- | ||
Line 121: | Line 122: | ||
|- | |- | ||
| 03:40 | | 03:40 | ||
− | | In '''linspace,''' the '''start''' and '''stop''' points can be | + | | In '''linspace,''' the '''start''' and '''stop''' points can be integers, decimals or '''constants'''. |
|- | |- | ||
Line 133: | Line 134: | ||
|- | |- | ||
|03:58 | |03:58 | ||
− | | So type '''linspace brackets minus pi comma pi comma 100 '''and | + | | So, type: '''linspace brackets minus pi comma pi comma 100 '''and press '''Enter'''. |
|- | |- | ||
Line 141: | Line 142: | ||
|- | |- | ||
|04:15 | |04:15 | ||
− | | Now, let us save this to a variable, say '''t'''. Press '''Enter'''. | + | | Now, let us '''save''' this to a variable, say '''t'''. Press '''Enter'''. |
|- | |- | ||
| 04:22 | | 04:22 | ||
− | | If we now type '''len bracket t '''and press '''Enter''', we will get the number of points between '''minus''' '''pi''' | + | | If we now type: '''len bracket t '''and press '''Enter''', we will get the number of points between '''minus pi''' and '''pi'''. |
|- | |- | ||
Line 153: | Line 154: | ||
|- | |- | ||
| 04:37 | | 04:37 | ||
− | | Next, let's try and plot a '''cosine | + | | Next, let's try and plot a '''cosine''' curve between '''minus pi''' and''' pi.''' |
|- | |- | ||
|04:43 | |04:43 | ||
− | | For this, we use the '''plot''' command. Type '''plot brackets t comma cos(t) '''and press '''Enter.''' | + | | For this, we use the '''plot''' command. Type: '''plot brackets t comma cos(t) '''and press '''Enter.''' |
|- | |- | ||
Line 169: | Line 170: | ||
|- | |- | ||
|05:21 | |05:21 | ||
− | | And then | + | | And then plot by typing '''plot(t comma cosine) '''and press '''Enter'''. |
|- | |- | ||
| 05:31 | | 05:31 | ||
− | | To clear the '''plot''', we have to use the '''clf()''' function. This avoids overlapping of new | + | | To clear the '''plot''', we have to use the '''clf()''' function. This avoids overlapping of new plots over older plots. |
|- | |- | ||
| 05:42 | | 05:42 | ||
− | | In the '''console''', type '''clf() '''and press '''Enter. '''The previous '''plot''' is cleared and a blank '''plot window''' is displayed. | + | | In the '''console''', type: '''clf() '''and press '''Enter. '''The previous '''plot''' is cleared and a blank '''plot window''' is displayed. |
|- | |- | ||
| 05:56 | | 05:56 | ||
− | | Now, let's try to plot a '''sine | + | | Now, let's try to plot a '''sine''' plot. |
|- | |- | ||
|06:00 | |06:00 | ||
− | | Type '''plot brackets t comma sin(t) '''and press '''Enter.''' A '''sine plot '''is displayed. | + | | Type: '''plot brackets t comma sin(t) '''and press '''Enter.''' A '''sine plot '''is displayed. |
|- | |- | ||
| 06:14 | | 06:14 | ||
− | | To study the | + | | To study the plot better on the''' plot window,''' we can use various options that are available on it. |
Let us have a look at these options. | Let us have a look at these options. | ||
|- | |- | ||
| 06:25 | | 06:25 | ||
− | | Moving the mouse pointer along the '''plot''' gives us the location of each | + | | Moving the '''mouse''' pointer along the '''plot''' gives us the location of each point on the plot. |
|- | |- | ||
| 06:33 | | 06:33 | ||
− | | Notice here | + | | Notice here, at the bottom left of the window, there are a few buttons. |
|- | |- | ||
|06:39 | |06:39 | ||
− | | The right-most among them is for saving the file. Just click on it and type the | + | | The right-most among them is for saving the file. Just click on it and type the file name. |
|- | |- | ||
|06:47 | |06:47 | ||
− | | Let us save the '''plot''' by the name '''sin underscore curve''' in '''pdf format'''. | + | | Let us '''save''' the '''plot''' by the name '''sin underscore curve''' in '''pdf format'''. |
|- | |- | ||
| 06:54 | | 06:54 | ||
− | | Click on the dropdown here.As you can see, there are many formats in which to save the | + | | Click on the dropdown here. As you can see, there are many formats in which to save the file. |
Formats like '''png, eps, pdf''', and '''ps''' are available. | Formats like '''png, eps, pdf''', and '''ps''' are available. | ||
Line 219: | Line 220: | ||
|- | |- | ||
| 07:14 | | 07:14 | ||
− | | To the left of the '''save '''button, is the '''slider | + | | To the left of the '''save '''button, is the '''slider''' button. Using this button, we can specify the margins of the''' plot window'''. |
|- | |- | ||
| 07:24 | | 07:24 | ||
− | | To the left of the '''slider | + | | To the left of the '''slider''' button is the '''zoom''' button . It is used to '''zoom''' into the '''plot'''. Just specify the region to '''zoom''' into. |
− | Just specify the region to '''zoom''' into. | + | |
|- | |- | ||
| 07:37 | | 07:37 | ||
− | | The button to the left of '''zoom '''can be used to move the '''axes '''of the '''plot'''. | + | | The button to the left of '''zoom, '''can be used to move the '''axes '''of the '''plot'''. |
|- | |- | ||
Line 240: | Line 240: | ||
|- | |- | ||
| 07:57 | | 07:57 | ||
− | | The last one is ''''home'''' referring to the initial '''plot. ''' | + | | The last one is ''''home'''', referring to the initial '''plot. ''' |
|- | |- | ||
Line 250: | Line 250: | ||
| Plot '''(sin(x) multiplied by sin(x)) divided by x'''. | | Plot '''(sin(x) multiplied by sin(x)) divided by x'''. | ||
− | 1. Save the '''plot''' as '''sinsquarebyx dot pdf''' | + | 1. '''Save''' the '''plot''' as '''sinsquarebyx dot pdf'''. |
2. '''Zoom''' and find the '''maxima'''. | 2. '''Zoom''' and find the '''maxima'''. | ||
Line 258: | Line 258: | ||
|- | |- | ||
| 08:26 | | 08:26 | ||
− | |This brings us to the end of this tutorial. In this tutorial, we have learnt to | + | |This brings us to the end of this tutorial. In this tutorial, we have learnt to: |
− | + | start '''IPython''' with '''pylab''', | |
− | + | use the '''linspace''' function to create equally spaced points in a region, | |
|- | |- | ||
|08:42 | |08:42 | ||
− | | | + | |find the length of sequences using '''len''' '''function''', |
− | + | plot mathematical functions using '''plot''', | |
− | + | clear drawing area using '''clf'''. | |
|- | |- | ||
|08:53 | |08:53 | ||
− | | | + | |usage of buttons in the '''UI''' of the plot window such as -<br/> '''save''', '''zoom,''' '''move axis''', '''back and forward, ''' '''Home. ''' |
|- | |- | ||
Line 280: | Line 280: | ||
| Here are some self assessment questions for you to solve - | | Here are some self assessment questions for you to solve - | ||
− | 1. Create 100 equally spaced points between '''minus pi by 2''' and '''pi by 2''' | + | 1. Create 100 equally spaced points between '''minus pi by 2''' and '''pi by 2'''. |
|- | |- | ||
Line 292: | Line 292: | ||
|- | |- | ||
| 09:26 | | 09:26 | ||
− | | And the answers | + | | And the answers are- |
We use the command '''linspace(minus pi by 2 comma pi by 2 comma 100)''' to create 100 equally spaced lines between the points '''minus pi by 2''' and '''pi by 2'''. | We use the command '''linspace(minus pi by 2 comma pi by 2 comma 100)''' to create 100 equally spaced lines between the points '''minus pi by 2''' and '''pi by 2'''. | ||
Line 306: | Line 306: | ||
|- | |- | ||
| 10:06 | | 10:06 | ||
− | | The video at the following link summarises the Spoken Tutorial project. If you do not have good bandwidth, you can download and watch it. | + | | The video at the following link summarises the '''Spoken Tutorial''' project. If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 10:16 | | 10:16 | ||
− | | We conduct workshops using Spoken Tutorials and give | + | | We conduct workshops using Spoken Tutorials and give certificates. Please contact us. |
|- | |- | ||
Line 323: | Line 323: | ||
|- | |- | ||
| 10:39 | | 10:39 | ||
− | | Do you have any general / technical questions? Please visit the forum given in | + | | Do you have any general / technical questions? Please visit the forum given in this link. |
|- | |- | ||
Line 335: | Line 335: | ||
|- | |- | ||
| 11:00 | | 11:00 | ||
− | | The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India | + | | The Spoken Tutorial project is funded by '''NMEICT, MHRD,''' Govt. of India. |
|- | |- | ||
| 11:07 | | 11:07 | ||
− | | This is Usha from IIT Bombay signing off. Thanks for watching. | + | | This is Usha from '''IIT Bombay''', signing off. Thanks for watching. |
|} | |} |
Latest revision as of 17:27, 11 June 2019
Time | Narration |
00:01 | Hello friends! Welcome to the tutorial on using plot command interactively in IPython. |
00:08 | At the end of this tutorial, you will be able to:
create simple plots of mathematical functions, use the Plot window to study plots better. |
00:20 | To record this tutorial, I am using:
Ubuntu Linux 14.04 operating system, Python 3.4.3 and IPython 5.1.0 |
00:34 | Pre-requisites to practise this tutorial are -
you should know how to run basic Python commands on the ipython console. |
00:44 | If not, for relevant Python tutorials, please visit this website. |
00:50 | Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously. |
00:58 | Now, type ipython3 and press Enter. |
01:05 | Let us initialise the pylab package. Type: percentage pylab and press Enter. |
01:16 | Let's first understand what is Pylab. |
01:20 | Pylab is a convenient Python module
which provides- plotting functionality and has mathematical and scientific functions. |
01:32 | After running percentage pylab in the iPython console, you will see a message-
“Using matplotlib backend: TkAgg ”. |
01:41 | This means matplotlib is running. |
01:45 | But sometimes you may get an error that says-
“ImportError: No module named matplotlib”. |
01:55 | In such cases, you have to install matplotlib and run this command again. |
02:02 | Let's come back to the ipython console. Type 'linspace' followed by a question mark in ipython console. Press Enter. |
02:14 | Please note that the command is linspace and not linespace. |
02:20 | The displayed information says that
linspace returns evenly spaced numbers which are calculated over the interval start and stop. |
02:34 | Press q to exit the documentation and return to the console. |
02:41 | Let's try to generate 100 points from 1 to 100. Type: linspace brackets 1 comma 100 comma 100 |
02:58 | Here, 1 is the start , 100 is the stop and the next 100 is the number of points. Now, press Enter. |
03:09 | As you can see, a sequence of numbers from 1 to 100 is displayed. |
03:15 | Now let's try to generate 200 points between 0 and 1. |
03:21 | We do that by typing linspace brackets 0 comma 1 comma 200 and press Enter. |
03:36 | Here is the expected sequence of numbers. |
03:40 | In linspace, the start and stop points can be integers, decimals or constants. |
03:48 | Let us now learn about the len function. |
03:52 | First we will generate 100 points between minus pi and pi. |
03:58 | So, type: linspace brackets minus pi comma pi comma 100 and press Enter. |
04:10 | Here 'pi' is a constant defined by pylab. |
04:15 | Now, let us save this to a variable, say t. Press Enter. |
04:22 | If we now type: len bracket t and press Enter, we will get the number of points between minus pi and pi. |
04:32 | len function gives the no. of elements present in a given sequence. |
04:37 | Next, let's try and plot a cosine curve between minus pi and pi. |
04:43 | For this, we use the plot command. Type: plot brackets t comma cos(t) and press Enter. |
04:59 | As you can see from the cosine plot, cos(t) gets the cosine value at every point corresponding to point t. |
05:09 | We can also assign the value of cos(t) to a variable cosine by typing cosine equals to cos(t). Press Enter. |
05:21 | And then plot by typing plot(t comma cosine) and press Enter. |
05:31 | To clear the plot, we have to use the clf() function. This avoids overlapping of new plots over older plots. |
05:42 | In the console, type: clf() and press Enter. The previous plot is cleared and a blank plot window is displayed. |
05:56 | Now, let's try to plot a sine plot. |
06:00 | Type: plot brackets t comma sin(t) and press Enter. A sine plot is displayed. |
06:14 | To study the plot better on the plot window, we can use various options that are available on it.
Let us have a look at these options. |
06:25 | Moving the mouse pointer along the plot gives us the location of each point on the plot. |
06:33 | Notice here, at the bottom left of the window, there are a few buttons. |
06:39 | The right-most among them is for saving the file. Just click on it and type the file name. |
06:47 | Let us save the plot by the name sin underscore curve in pdf format. |
06:54 | Click on the dropdown here. As you can see, there are many formats in which to save the file.
Formats like png, eps, pdf, and ps are available. |
07:08 | We have to specify the format that we prefer at the time of saving. |
07:14 | To the left of the save button, is the slider button. Using this button, we can specify the margins of the plot window. |
07:24 | To the left of the slider button is the zoom button . It is used to zoom into the plot. Just specify the region to zoom into. |
07:37 | The button to the left of zoom, can be used to move the axes of the plot. |
07:41 | The next two buttons with left and right arrow icons, change the state of the plot. |
07:48 | It takes us to the previous or next state of the plot. It acts like the back and forward button in a browser. |
07:57 | The last one is 'home', referring to the initial plot. |
08:03 | Pause the video here, try out the following exercise and then resume the video. |
08:09 | Plot (sin(x) multiplied by sin(x)) divided by x.
1. Save the plot as sinsquarebyx dot pdf. 2. Zoom and find the maxima. 3. Bring it back to initial position. |
08:26 | This brings us to the end of this tutorial. In this tutorial, we have learnt to:
start IPython with pylab, use the linspace function to create equally spaced points in a region, |
08:42 | find the length of sequences using len function,
plot mathematical functions using plot, clear drawing area using clf. |
08:53 | usage of buttons in the UI of the plot window such as - save, zoom, move axis, back and forward, Home. |
09:04 | Here are some self assessment questions for you to solve -
1. Create 100 equally spaced points between minus pi by 2 and pi by 2. |
09:15 | 2. How can we find the length of a sequence ? |
09:19 | 3. What will the command linspace(minus pi comma pi comma 100) do? |
09:26 | And the answers are-
We use the command linspace(minus pi by 2 comma pi by 2 comma 100) to create 100 equally spaced lines between the points minus pi by 2 and pi by 2. |
09:43 | len(sequence underscore name) is the function used to find out the length of a sequence. |
09:50 | The command linspace(minus pi comma pi comma 100) will return 100 evenly spaced samples from -pi to pi including both minus pi and pi. |
10:06 | The video at the following link summarises the Spoken Tutorial project. If you do not have good bandwidth, you can download and watch it. |
10:16 | We conduct workshops using Spoken Tutorials and give certificates. Please contact us. |
10:24 | Do you have questions in THIS Spoken Tutorial? |
10:27 | Choose the minute and second where you have the question. Explain your question briefly.
Someone from the FOSSEE team will answer them. Please visit this site. |
10:39 | Do you have any general / technical questions? Please visit the forum given in this link. |
10:46 | The FOSSEE team coordinates coding of solved examples of popular books. |
10:51 | We give honorarium and certificates for those who do this. For more details, please visit this site. |
11:00 | The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India. |
11:07 | This is Usha from IIT Bombay, signing off. Thanks for watching. |