Python/C2/Saving-plots/English-timed
From Script | Spoken-Tutorial
Timing | Narration |
---|---|
0:00 | Hello and welcome to the tutorial on "Saving plots". |
0:04 | At the end of this tutorial, you will be able to,
|
0:13 | Before beginning this tutorial,we would suggest you to complete the tutorial on "Using plot interactively". |
0:19 | Now, Start your IPython interpreter with the command ipython hyphen pylab <Pause> |
0:30 | As you know, it will start your IPython interpreter with the required python modules for plotting and saving your plots. |
0:36 | To start with, let us plot a sine wave from minus 3 pi to 3 pi. |
0:43 | Let us start by calculating the required points for the plot. |
0:45 | It can be done using linspace as, |
0:51 | Type x = linspace within brackets minus 3 into pi comma 3 into pi comma 100 |
0:59 | We have stored the required points in x. |
1:03 | Now let us plot the points using the plot statement. |
1:18 | Done! |
1:19 | we have made a very basic sine plot, now let us see how to save the plot for future use so that you can embed the plot in your reports. |
1:32 | For saving the plot, we will use savefig() function. |
1:36 | For this we shall keep the plot window open alongside the terminal. |
1:40 | The statement is,savefig within brackets in single quotes slash home slash fossee slash sine dot png |
1:52 | Notice that savefig function takes one argument which is the filename, the last 3 characters after the. in the filename is the extension and type of the file which determines the format in which you want to save. |
2:10 | Also, note that we gave the full path or the absolute path to which we want to save the file. |
2:18 | Here we have used an extension dot png which means we want to save the image as a PNG file. |
2:25 | Now let us locate the file sine dot png which we had saved a while ago. |
2:32 | We have saved the file to slash home slash fossee so let us navigate to slash home slash fossee using thefile browser. |
2:49 | Yes, the file sine dot png is here. |
2:52 | Let us open it and check. |
2:57 | So in-order to save a plot, we use savefig function. |
3:05 | dot savefig can save the plot in many formats, such as pdf - portable document format, ps - post script, eps - encapsulated post script, svg - scalable vector graphics, png - portable network graphics which support transparency etc. |
3:24 | Pause the video here, try out the following exercise and resume the video. |
3:29 | Save the sine plot in the EPS format which can be embedded in LaTeX documents. |
3:37 | We still have the sine plot with us,let us now save the plot as sine dot eps. |
3:49 | Now, We will save the plot using the function savefig, so you can type savefig within brackets in single quotes slash home slash fossee slash sine dot eps and hit enter |
4:04 | Now let us go to slash home slash fossee and see the new file created. |
4:13 | Yes! the new file sine dot epsis here. |
4:18 | Pause the video here, try out the following exercise and resume the video. |
4:23 | Save the sine plot in PDF, PS and SVG formats. |
4:31 | This brings us to the end of this tutorial. |
4:34 | In this tutorial,we have learnt to, Save plots using the savefig() function. |
4:38 | then Save the plots in different formats like - pdf - ps - png - svg - eps |
4:45 | Here are some self assessment questions for you to solve |
4:48 | 1. Which command is used to save a plot. saveplot() savefig() savefigure() saveplt() |
4:59 | 2. savefig('sine.png') saves the plot in, |
5:04 | The root directory (on GNU/Linux, Unix based systems), c colon slash (on windows). |
5:14 | The second option. Will result in an error as full path is not supplied. |
5:18 | The third one.The current working directory. |
5:21 | and final option is Predefined directory like /documents. |
5:26 | And now, the answers, |
5:28 | 1.To save a plot,we use the savefig() function. |
5:33 | 2. Whenever we save a file,it gets saved in the current working directory. |
5:38 | Hope you have enjoyed and found it useful. |
Contributors and Content Editors
Gaurav, Jyotisolanki, Minal, PoojaMoolya, Sandhya.np14, Sneha