 Good morning everybody. We will start with the session. Interactive plotting is what we will start with. Please start i Python with the command i Python minus philab. The slides whenever you see an i n that means those are commands you have to type. So start i Python with the command i Python minus philab. As a general rule whenever you see that i n square bracket that means you have to type it. On your screen you will see i n with a number. We are skipping that number because on different people screen it will be a different number. We do not want you to get confused with us putting one number and you seeing a different number. Let me repeat that i n square bracket is a signal that you have to type the command. We are not giving the number within the square bracket but you will see a number in your screen. So after you type i Python minus philab you will see the i Python prompt which is that i n. So type those two commands which appear there. You should see this picture on your screen. You should have got a picture like this on your screen. Very simple. Let us move on. What exactly did we do? When we said p equal to lint space minus pi pi 100, what we did is created 100 points in the range minus pi to pi. We can understand that better if you attempt to print what is p 0, what is the that is what is the first element, what is the last element and what is the length as you can see minus pi plus pi and 100. So lint space produces a list of the values, equi-spaced values. We can look at the dock string of lint space, i Python gives you the facility to consult the dock string by that this will run for many pages. So we will not go all over. Please note that it says return evenly spaced numbers over a specified interval that is all. That is the simplest. So you specify the start, stop and the number it returns evenly spaced numbers over that specified interval which is exactly what we want. What simply plots the two arguments with default properties? If you ever had to plot in other languages you would have seen how much work it is in those languages and how simple it is in Python. Now we noted that we said plot simply plots with default properties. That gives rise to the natural question. So can we overwrite those properties? Yes we can and we should often do that and that is for dressing up or embellishing your plots. Try out the commands here. This is the simplest type of embellishment. You can specify an output color for the plot. You can also specify the line width. You can notice that it has become thicker. CLF will clear your plotting area. Instead of a continuous line we have plotted with a dotted line. Once again plot question mark will give you lot more information. I will not show it here on the screen. Please check it out because my screen is small and at the large letters you will not see enough. On your screen you should be able to see enough to read. Remember this. Then in doubt just a question mark after the command will tell you. Let us move on. Normally for a plot you need to do lot more when you present one. We add a title here. Let us check it out what happens. So what does this command do? x equal to linspace minus 2, 4, 50. In the range minus 2 to 4 it will produce 50 equi-spaced points. x of 0 will be minus 2, x of 49 will be 4 and every point there will be equi-spaced. We plot minus x square plus 4x minus 5. Is that what we are supposed to plot? Let me verify. Yes, minus x square plus 4x minus 5 in red color at a line width of 2. Now this is what you will see. I should have cleared it. Here is the chart. Now you would like to give this a title. Simply you can see the title. We can also use latex. Whatever is enclosed within dollar is a latex math expression and Python will type set it using latex for you. See the difference? Actually I should not have done it as x star x. If I am going to use latex, let us redo it. You can see the title now. It looks more like a mathematical equation than a programming expression. Let us move on. You can also label the axis once again using latex if you want to. You can see the x label. There is a x here. Now the y label makes its appearance. It is here. As you can see, each feature or each command is additive. Whatever you do, it adds to the existing picture. So, we had the basic graph. Then we added a title. It appeared here. We added a x label that appeared at the bottom. We added a y label that appeared in the left and so on. So, the natural way is for commands to be additively going on to the output. This is on the other sides of the outside title and all are outside the chart area. Then inside the chart area, you could do what is called an annotation. Let us do an annotation called local maximum. You could do an annotation for anything. Try it out. Let us move on to the before we move on. Remember the one point about the annotation. The x y argument is a tuple that gives the location of the text. So, you want at minus 2 comma minus 1. That is x value 2 and y value minus 1. Unfortunately, I do not see it appearing here. So, minus 2 comma 1 is above this. That is why it does not appear. It is not part of the chart. So, let me change it. Let us actually see where is the maximum. The maximum is at 2 comma minus 2 approximately. 2 comma minus 1 is an error. So, it is not coming on the screen. I made an error. I typed it as minus 2 comma 1. So, there was no minus 2 comma 1 within. Now, you can see the word local maximum appearing here. The coordinates given are what are called data coordinates. They are not connected to the pixels, the size of the picture. They are connected to the x y values. So, where x y value is 2 and minus 1 is where it will be shown. Let us look at the chart we have produced or let us look at the one of the earlier charts we produced. This chart, you do not get a feel for how the curve behaves because the curve is touching the axis on both sides. You would like to have some space around. In a different context, let me show you something else. If you look at this picture, for example, there is this space on the left, there is this space on the right, there is left and the curve is actually touching the axis in the bottom on the top. So, we would like to give some reduce the space on the right and the left and increase the space on the top. So, often we want to the default decisions of the plotting tool about how to frame the plot or not something we are happy with. So, the way to change it is to use x lim and y lim. Let me have the chart redone then reproduce this. Now, we want to increase the margins on the right and the left. How do you go about doing that is what we will see. The command we use is x lim. x lim gives you the current limit of x, limits of x and y lim gives you the current limits of y. When invoked without any arguments, they will give you that. When invoked with arguments, they will set the new limits. Let us look at that. So, this is the x limit as you can see from minus 2 to 4 and this is the y limit minus 18 to 0. So, we would like to actually increase it this to say minus 3 to 5. So, there is some space we can do. Now, if you see the figure immediately you will see space has appeared on both sides. Same way you can change the y limit. Remember, when invoked without any arguments x lim and y lim will tell you what is the current drawing areas limits. When invoked with arguments, they will reset them. Let us put all of this together. This consists of 4 plots x equal to y equal to x and y equal to minus x sin x and cos x over minus pi 2 plus pi and the plotting of x lim and x lim area has been reduced using x lim, so that there is no space on the both sides. Please do this exercise, so that we can say that whatever we have seen so far we can completely try it out once. Please add a title, please add a just add a title and the x and y labels. The 4 plots are y equal to x, y equal to minus x, y equal to sin x and y equal to cos x from minus pi to plus pi. I presume you have been able to do that. Let us move on to the next item. In fact, that gives a good way to move on. Exactly how did I do it? Want to find out? Percentage HIST gives you a list of all the commands I typed up to now. You try it in your machine, you will see it. You can see from the beginning all the commands we typed are here. Now, the 4 commands I used to produce that chart was CLF of course, then plot p comma p for y equal to x, plot p comma minus p for y equal to minus x, p was already defined, then plot p and sin p, plot p and cos p, then set x limit. Now, let us solve it. Now, if the way you work is interactively, you type commands to try out things. But once you have decided on what you have, what is the mechanism or what is the method to use in order to achieve what you want, you do not want to type again. You do not want to be going on typing the same thing repeatedly. So, you can save the commands you typed into a script and run it. Try out the HIST command first. It will give you the last 10 commands and so on. So, these are the 4 commands I used. I have to add a linspace command. Now, if I can save this 4 somewhere, then I can reuse these 4 in order to repeatedly do the same thing and that is what we talk about. Percentage save is the command. The first argument it takes is the name of the script in which you want to save it, then the line numbers. The command as shown on the screen says save line number 1, line number 3, 4, 5, 6 and line number 8 into a file called plot underscore script dot pi. The command on the screen says save line number 1, line number 3, 4, 5, 6 and line number 8 into a file called plot underscore script dot py. So, when you run the percentage save command it will tell you what commands are written and you can see the 4 plot dot py has been created as a file in the system. Now, if you open it with an editor, we can see its contents. It is the same lines I actually saved. It is a regular file. I am adding the linspace line. Now this 4 plot is something we can run any time we want if we want to redo this chart. There are some additional issues. We will do it now and be done with it. We will talk about why the minus i later, 4 plot dot py. So, it reproduces the plot without having to type it line by line. This is how you will find yourself working in Python if you are doing any preparation of plots. You will interactively try out a few things. Once it is settled, save it into a script and use the script to generate whatever we want. Of course, rarely we want to just show the chart. We may have to save it into a graphic file PNG and put it into a report and so on. How to do all of that we will see after the break.