Difference between revisions of "Python/C2/Saving-plots/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
|-
+
| 0:00
+
| Hello and welcome to the tutorial on "Saving plots".
+
  
 
|-
 
|-
| 0:04
+
| 00:00
| At the end of this tutorial, you will be able to,
+
| Hello and welcome to the tutorial on '''"Saving plots"'''.
  
# Save plots using savefig()function.
+
|-
# Save plots in different formats.
+
| 00:04
 +
| At the end of this tutorial, you will be able to-
 +
'''Save''' plots using '''savefig()''' function.
 +
Save '''plot'''s in different formats.
  
 
|-
 
|-
| 0:13
+
| 00:13
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Using plot interactively".
+
| Before beginning this tutorial, we would suggest you to complete the tutorial on '''"Using plot interactively"'''.
  
 
|-
 
|-
|0:19
+
|00:19
|Now, Start your IPython interpreter with the command ipython hyphen pylab
+
|Now, start your '''IPython interpreter''' with the command '''ipython hyphen pylab'''.
  
 
|-
 
|-
|0:30
+
|00:30
|As you know, it will start your IPython interpreter with the required python modules for plotting and saving your plots.
+
|As you know, it will start your IPython interpreter with the required '''python module'''s for plotting and saving your plots.
  
 
|-
 
|-
| 0:36
+
| 00:36
| To start with, let us plot a sine wave from minus 3 pi to 3 pi.
+
| To start with, let us plot a '''sine wave''' from '''minus 3 pi to 3 pi'''.
  
 
|-
 
|-
| 0:43
+
| 00:43
 
| Let us start by calculating the required points for the plot.
 
| Let us start by calculating the required points for the plot.
  
 
|-
 
|-
| 0:45
+
| 00:45
| It can be done using linspace as,
+
| It can be done using '''linspace''' as-
  
 
|-
 
|-
|0:51
+
|00:51
|You can Type x = linspace within brackets minus 3 into pi comma 3 into pi comma 100  
+
|You can type: '''x = linspace''' within brackets '''minus 3 into pi comma 3 into pi comma 100'''.
  
 
|-
 
|-
0:59
+
00:59
| We have stored the required points in x.  
+
| We have stored the required points in 'x'.  
  
 
|-
 
|-
|1:03
+
|01:03
|Now let us plot the points using the plot statement.So type plot (x,sinx)   
+
|Now, let us plot the points using the ''''plot' statement'''. So, type: '''plot (x, sinx)'''.  
  
 
|-
 
|-
1:18
+
01:18
| Done!
+
| Done! 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 '''report'''s.
  
 
|-
 
|-
| 1:19
+
| 01:32
| 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.
+
| So, saving the plot, we will use '''savefig()''' function.  
  
 
|-
 
|-
| 1:32
+
|01:36
| So saving the plot, we will use savefig() function.  
+
|For this, we shall keep the '''plot window''' open alongside the '''terminal'''.
  
 
|-
 
|-
|1:36
+
|01:40
|For this we shall keep the plot window open alongside the terminal.
+
| The statement is: '''savefig''' within brackets in single quotes '''slash home slash fossee slash sine dot png'''.
  
 
|-
 
|-
|1:40
+
| 01:52
| The statement is savefig within brackets in single quotes slash home slash fossee slash sine dot png
+
| 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'''.
  
 
|-
 
|-
| 1:52
+
| 02:10
| 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.
+
| Also, note that we gave the full '''path''' or the '''absolute path''' to which we want to save the file.
  
 
|-
 
|-
| 2:10
+
| 02:18
| Also, note that we gave the full path or the absolute path to which we want to save the file.
+
| Here, we have used an extension '''dot png''' which means we want to save the image as a '''PNG file'''.
  
 
|-
 
|-
| 2:18
+
|02:25
| Here we have used an extension dot png which means we want to save the image as a PNG file.
+
|Now, let us locate the file '''sine dot png''' which we had saved a while ago.
  
 
|-
 
|-
|2:25
+
| 02:32
|Now let us locate the file sine dot png which we had saved a while ago.
+
| We have saved the file to '''slash home slash fossee'''. So, let us navigate to  '''slash home slash fossee''' using the file browser.
  
 
|-
 
|-
| 2:32
+
| 02:49
| We have saved the file to slash home slash fossee so let us navigate to  slash home slash fossee  using thefile browser.
+
| Yes, the file '''sine dot png''' is here.  
  
 
|-
 
|-
| 2:49
+
| 02:52
| Yes, the file sine dot png  is here.  
+
| Let us open it and check.
  
 
|-
 
|-
| 2:52
+
| 02:57
| Let us open it and check
+
| So, in-order to save a plot, we use '''savefig()''' function.
  
 
|-
 
|-
| 2:57
+
| 03:05
| So in-order to save a plot , we use savefig function.
+
| '''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: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
+
| 03:24
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
|3:29
+
|03:29
|Save the sine plot in the EPS format which can be embedded in LaTeX documents.
+
|Save the '''sine plot''' in the '''EPS format''' which can be embedded in '''LaTeX document'''s.
  
 
|-
 
|-
| 3:37
+
| 03:37
| We still have the sine plot with us,let us now save the plot as sine dot eps.
+
| We still have the '''sine plot''' with us, let us now '''save''' the plot as '''sine dot eps'''.
  
 
|-
 
|-
| 3:49
+
| 03: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
+
| 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
+
| 04:04
| Now let us go to slash home slash fossee  and see the new file created.
+
| Now, let us go to: '''slash home slash fossee''' and see the new file created.
  
 
|-
 
|-
| 4:13
+
| 04:13
| Yes! the new file sine dot epsis here.
+
| Yes! the new file '''sine dot eps''' is here.
  
 
|-
 
|-
| 4:18
+
| 04:18
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
|4:23
+
|04:23
|Save the sine plot in PDF, PS and SVG formats.
+
|Save the '''sine plot''' in '''PDF, PS''' and '''SVG format'''s.
  
 
|-
 
|-
| 4:31
+
| 04:31
 
| This brings us to the end of this tutorial.  
 
| This brings us to the end of this tutorial.  
  
 
|-
 
|-
|4:34
+
|04:34
|In this tutorial,we have learnt to, Save plots using the savefig() function.
+
|In this tutorial, we have learnt to save plots using the '''savefig()''' function.
  
 
|-
 
|-
| 4:38
+
| 04:38
| then Save the plots in different formats like - pdf - ps - png - svg - eps
+
| Then save the plots in different formats like - '''pdf, ps, png, svg, eps.'''
  
 
|-
 
|-
| 4:45
+
| 04:45
| Here are some self assessment questions for you to solve
+
| Here are some self assessment questions for you to solve-
  
 
|-
 
|-
|4:48
+
|04:48
|1. Which command is used to save a plot. saveplot() savefig() savefigure() saveplt()
+
|1. Which command is used to save a plot. '''saveplot(), savefig(), savefigure(), saveplt()'''?
  
 
|-
 
|-
|4:59
+
|04:59
| 2. savefig('sine.png') saves the plot in,
+
| 2. '''savefig('sine.png')''' saves the plot in-
  
 
|-
 
|-
| 5:04
+
| 05:04
| The root directory (on GNU/Linux, Unix based systems), c colon slash (on windows).
+
| The '''root''' directory (on GNU/Linux, Unix based systems)- '''c colon slash''' (on windows).
  
 
|-
 
|-
| 5:14
+
| 05:14
| The second option. Will result in an error as full path is not supplied.
+
| The second option- Will result in an error as full path is not supplied.
  
 
|-
 
|-
| 5:18
+
| 05:18
| The third one.The current working directory.
+
| The third one- The current working directory.
  
 
|-
 
|-
| 5:21
+
| 05:21
| and final option is Predefined directory like /documents.
+
| and final option is- Predefined directory like "/documents".
  
 
|-
 
|-
| 5:26
+
|05:26
| And now, the answers,
+
| And now, the answers-
  
 
|-
 
|-
| 5:28
+
| 05:28
|1.To save a plot,we use the savefig() function.
+
|1. To save a plot, we use the '''savefig()''' function.
  
 
|-
 
|-
|5:33
+
|05:33
|2. Whenever we save a file,it gets saved in the current working directory.
+
|2. Whenever we save a file, it gets saved in the current working directory.
  
 
|-
 
|-
| 5:38
+
| 05:38
| Hope you have enjoyed and found it useful.THanks
+
| Hope you have enjoyed and found it useful. Thanks.

Latest revision as of 10:32, 27 March 2017

Time Narration
00:00 Hello and welcome to the tutorial on "Saving plots".
00:04 At the end of this tutorial, you will be able to-

Save plots using savefig() function. Save plots in different formats.

00:13 Before beginning this tutorial, we would suggest you to complete the tutorial on "Using plot interactively".
00:19 Now, start your IPython interpreter with the command ipython hyphen pylab.
00:30 As you know, it will start your IPython interpreter with the required python modules for plotting and saving your plots.
00:36 To start with, let us plot a sine wave from minus 3 pi to 3 pi.
00:43 Let us start by calculating the required points for the plot.
00:45 It can be done using linspace as-
00:51 You can type: x = linspace within brackets minus 3 into pi comma 3 into pi comma 100.
00:59 We have stored the required points in 'x'.
01:03 Now, let us plot the points using the 'plot' statement. So, type: plot (x, sinx).
01:18 Done! 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.
01:32 So, saving the plot, we will use savefig() function.
01:36 For this, we shall keep the plot window open alongside the terminal.
01:40 The statement is: savefig within brackets in single quotes slash home slash fossee slash sine dot png.
01: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.
02:10 Also, note that we gave the full path or the absolute path to which we want to save the file.
02:18 Here, we have used an extension dot png which means we want to save the image as a PNG file.
02:25 Now, let us locate the file sine dot png which we had saved a while ago.
02:32 We have saved the file to slash home slash fossee. So, let us navigate to slash home slash fossee using the file browser.
02:49 Yes, the file sine dot png is here.
02:52 Let us open it and check.
02:57 So, in-order to save a plot, we use savefig() function.
03: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.

03:24 Pause the video here, try out the following exercise and resume the video.
03:29 Save the sine plot in the EPS format which can be embedded in LaTeX documents.
03:37 We still have the sine plot with us, let us now save the plot as sine dot eps.
03: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.
04:04 Now, let us go to: slash home slash fossee and see the new file created.
04:13 Yes! the new file sine dot eps is here.
04:18 Pause the video here, try out the following exercise and resume the video.
04:23 Save the sine plot in PDF, PS and SVG formats.
04:31 This brings us to the end of this tutorial.
04:34 In this tutorial, we have learnt to save plots using the savefig() function.
04:38 Then save the plots in different formats like - pdf, ps, png, svg, eps.
04:45 Here are some self assessment questions for you to solve-
04:48 1. Which command is used to save a plot. saveplot(), savefig(), savefigure(), saveplt()?
04:59 2. savefig('sine.png') saves the plot in-
05:04 The root directory (on GNU/Linux, Unix based systems)- c colon slash (on windows).
05:14 The second option- Will result in an error as full path is not supplied.
05:18 The third one- The current working directory.
05:21 and final option is- Predefined directory like "/documents".
05:26 And now, the answers-
05:28 1. To save a plot, we use the savefig() function.
05:33 2. Whenever we save a file, it gets saved in the current working directory.
05:38 Hope you have enjoyed and found it useful. Thanks.

Contributors and Content Editors

Gaurav, Jyotisolanki, Minal, PoojaMoolya, Sandhya.np14, Sneha