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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border=1 | '''Time''' | '''Narration''' |- |00:01 | Hello Friends. Welcome to the tutorial on "'''Saving Plots'''". |- | 00:06 | At the end of this tutorial, you will b...")
 
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
|-
 
|-
 
|00:01
 
|00:01
| Hello Friends. Welcome to the tutorial on "'''Saving Plots'''".  
+
| Hello friends! Welcome to the tutorial on "'''Saving Plots'''".  
  
 
|-
 
|-
Line 12: Line 12:
 
| At the end of this tutorial, you will be able to -
 
| At the end of this tutorial, you will be able to -
  
Save plots using '''savefig() function'''.
+
save '''plot'''s using '''savefig() function''',
  
Save plots in different formats.
+
save plots in different '''format'''s.
  
 
|-
 
|-
 
| 00:15
 
| 00:15
|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''',
  
 
'''IPython 5.1.0'''
 
'''IPython 5.1.0'''
Line 28: Line 28:
 
|-
 
|-
 
| 00:28
 
| 00:28
| To practise this tutorial, you should know how to use '''Plot Command interactively.
+
| To practise this tutorial, you should know how to use '''Plot''' command interactively.
  
If not, see the prerequisite '''Python''' tutorials on this website.
+
If not, see the prerequisite '''Python tutorials''' on this website.
  
 
|-
 
|-
Line 39: Line 39:
 
|-
 
|-
 
| 00:54
 
| 00:54
| Let us initialise the '''pylab''' package.
+
| Let us initialise the ''''pylab' package'''.
Type '''percentage pylab '''and press''' Enter'''
+
Type '''percentage pylab '''and press''' Enter'''.
  
 
|-
 
|-
Line 52: Line 52:
 
|-
 
|-
 
| 01:14
 
| 01:14
| To do this, type,
+
| To do this, type:
  
 
'''x equals to linspace(minus 3 star pi comma 3 star pi comma 100) '''in the '''console'''.
 
'''x equals to linspace(minus 3 star pi comma 3 star pi comma 100) '''in the '''console'''.
Line 58: Line 58:
 
|-
 
|-
 
| 01:28
 
| 01:28
| Let us '''plot''' a '''sine curve''' for the points stored in '''variable x'''
+
| Let us '''plot''' a '''sine curve''' for the points stored in '''variable x'''.
  
 
|-
 
|-
 
| 01:33
 
| 01:33
| Type '''plot(x comma sin(x)) '''in the '''console''' and press '''Enter. '''
+
| Type: '''plot(x comma sin(x)) '''in the '''console''' and press '''Enter. '''
  
 
Don't close the '''plot window''' for rest of the tutorial.
 
Don't close the '''plot window''' for rest of the tutorial.
Line 68: Line 68:
 
|-
 
|-
 
| 01:47
 
| 01:47
| Here you can see we have made a very basic '''sine plot'''. Now let us see how to save the '''plot.'''
+
| Here you can see we have made a very basic '''sine plot'''. Now let us see how to '''save''' the '''plot.'''
  
 
|-
 
|-
 
| 01:54
 
| 01:54
| For saving the plot, we will use the '''savefig() function.'''  
+
| For saving the plot, we will use the ''''savefig()' function.'''  
  
 
Syntax: '''savefig(fname)'''
 
Syntax: '''savefig(fname)'''
Line 80: Line 80:
 
|-
 
|-
 
| 02:05
 
| 02:05
| Type '''savefig('sine.png') '''and press''' Enter'''.
+
| Type: '''savefig('sine.png') '''and press''' Enter'''.
  
 
|-
 
|-
 
| 02:12
 
| 02:12
| This saves the file in '''present working directory'''.
+
| This saves the file in present '''working directory'''.
  
 
|-
 
|-
 
| 02:16
 
| 02:16
| The characters after the '''dot '''in the filename is the '''extension'''. It determines the format in which you want to save the file.
+
| The characters after the '''dot '''in the filename is the '''extension'''. It determines the '''format''' in which you want to '''save''' the file.
  
 
|-
 
|-
 
| 02:27
 
| 02:27
| To check current working directory, Type '''pwd '''in the '''console''' and press '''Enter'''
+
| To check the current working directory, type '''pwd '''in the '''console''' and press '''Enter'''.
  
 
|-
 
|-
 
| 02:34
 
| 02:34
| To save the file in a different directory, type full path of the directory before the filename.
+
| To save the file in a different directory, type full '''path''' of the directory before the filename.
Type '''savefig('slash home slash fossee slash sine.png')'''
+
Type: '''savefig('slash home slash fossee slash sine.png')'''
  
 
|-
 
|-
 
| 02:53
 
| 02:53
| Note that above''' file path '''is for''' Linux based file systems.'''
+
| Note that the above''' file path '''is for''' Linux''' based file systems.
  
 
|-
 
|-
 
| 02:59
 
| 02:59
| For''' Windows, '''give the entire file path as shown here. Here '''fossee''' is the '''username '''in''' Windows''' and '''sine.png '''file is to be saved on '''Desktop'''.
+
| For''' Windows, '''give the entire '''file path''' as shown here. Here '''fossee''' is the '''username '''in''' Windows''' and '''sine.png '''file is to be saved on '''Desktop'''.
  
 
|-
 
|-
Line 119: Line 119:
 
| We have saved the file to  
 
| We have saved the file to  
  
'''(slash)home(slash)fossee,'''
+
'''(slash)home(slash)fossee'''.
  
 
|-
 
|-
Line 131: Line 131:
 
|-
 
|-
 
| 03:46
 
| 03:46
| '''savefig''' can save the plot in many formats, such as
+
| '''savefig''' can save the plot in many formats such as-
  
 
'''pdf - portable document format, '''
 
'''pdf - portable document format, '''
Line 139: Line 139:
 
|-
 
|-
 
| 03:57
 
| 03:57
| '''eps - encapsulated post script, '''to be used with '''LaTeX '''documents
+
| '''eps - encapsulated post script, '''to be used with '''LaTeX '''documents,
  
 
'''svg - scalable vector graphics, '''
 
'''svg - scalable vector graphics, '''
  
'''png - portable network graphics '''
+
'''.png - portable network graphics '''.
  
 
|-
 
|-
Line 155: Line 155:
 
|-
 
|-
 
| 04:23
 
| 04:23
| Type '''savefig('slash home slash fossee slash sine.eps')''' and press '''Enter.'''
+
| Type: '''savefig('slash home slash fossee slash sine.eps')''' and press '''Enter.'''
  
 
|-
 
|-
Line 168: Line 168:
 
|-
 
|-
 
| 05:00
 
| 05:00
| 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:
  
 
1. Save plots using the '''savefig() '''function.
 
1. Save plots using the '''savefig() '''function.
  
 
2. Save the plots in different formats like
 
2. Save the plots in different formats like
''' pdf - ps - png - svg - eps'''
+
''' pdf, ps, png, svg''' and '''eps'''.
  
 
|-
 
|-
Line 180: Line 180:
  
 
1. Which command is used to save a '''plot'''?
 
1. Which command is used to save a '''plot'''?
'''saveplot()'''
+
'''saveplot()''',
  
'''savefig()'''
+
'''savefig()''',
  
'''savefigure()'''
+
'''savefigure()''',
  
 
'''saveplt()'''
 
'''saveplt()'''
  
2. '''savefig('sine.png')'''saves the '''plot''' in
+
2. '''savefig('sine.png')''' saves the '''plot''' in-
 
+
'''The root directory 'slash' (on GNU/Linux, Unix based systems), '<u>C</u>:' (on windows)'''
+
the '''root directory 'slash' (on GNU/Linux, Unix based systems), '<u>C</u>:' (on windows)''',
  
 
|-
 
|-
 
| 05:40
 
| 05:40
|Will result in an '''error''' as '''full path''' is not supplied.
+
|will result in an '''error''' as '''full path''' is not supplied,
  
The current '''working directory'''.
+
the current '''working directory''',
  
Predefined directory like “'''slash '''documents.”
+
predefined directory like “'''slash documents.”'''
  
 
|-
 
|-
 
| 05:50
 
| 05:50
| And the answers,
+
| And the answers are-
  
 
1. To save a plot, we use the '''savefig() function.'''
 
1. To save a plot, we use the '''savefig() function.'''
Line 214: Line 214:
 
|-
 
|-
 
| 06:07
 
| 06:07
|Please post your general queries on Python in this forum.
+
|Please post your general queries on '''Python''' in this forum.
  
 
|-
 
|-
 
| 06:12
 
| 06:12
|FOSSEE team coordinates the TBC project.
+
|'''FOSSEE''' team coordinates the '''TBC project'''.
  
 
|-
 
|-
 
| 06:16
 
| 06:16
| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. For more details, visit this website.
+
| '''Spoken Tutorial''' project is funded by '''NMEICT, MHRD,''' Govt. of India. For more details, visit this website.
  
 
|-
 
|-
 
| 06:25
 
| 06:25
| This is Prabhu from IIT Bombay (or FOSSEE, if you wish) signing off. Thank you.
+
| This is Prabhu from '''IIT Bombay''', signing off. Thank you.
  
 
|}
 
|}

Latest revision as of 16:38, 12 June 2019

Time Narration
00:01 Hello friends! Welcome to the tutorial on "Saving Plots".
00:06 At the end of this tutorial, you will be able to -

save plots using savefig() function,

save plots in different formats.

00:15 To record this tutorial, I am using:

Ubuntu Linux 14.04 operating system,

Python 3.4.3,

IPython 5.1.0

00:28 To practise this tutorial, you should know how to use Plot command interactively.

If not, see the prerequisite Python tutorials on this website.

00:40 Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously.

Now, type ipython3 and press Enter.

00:54 Let us initialise the 'pylab' package.

Type percentage pylab and press Enter.

01:05 Let us plot a sine curve from minus 3 pi to 3 pi.
01:10 First, we will calculate the required points for the plot.
01:14 To do this, type:

x equals to linspace(minus 3 star pi comma 3 star pi comma 100) in the console.

01:28 Let us plot a sine curve for the points stored in variable x.
01:33 Type: plot(x comma sin(x)) in the console and press Enter.

Don't close the plot window for rest of the tutorial.

01:47 Here you can see we have made a very basic sine plot. Now let us see how to save the plot.
01:54 For saving the plot, we will use the 'savefig()' function.

Syntax: savefig(fname)

savefig function takes one argument which is the filename.

02:05 Type: savefig('sine.png') and press Enter.
02:12 This saves the file in present working directory.
02:16 The characters after the dot in the filename is the extension. It determines the format in which you want to save the file.
02:27 To check the current working directory, type pwd in the console and press Enter.
02:34 To save the file in a different directory, type full path of the directory before the filename.

Type: savefig('slash home slash fossee slash sine.png')

02:53 Note that the above file path is for Linux based file systems.
02:59 For Windows, give the entire file path as shown here. Here fossee is the username in Windows and sine.png file is to be saved on Desktop.
03:15 Here we have used an extension dot png. This will ensure that the image is saved as a PNG file.
03:24 Now let us locate the file sine.png which we had saved earlier.
03:30 We have saved the file to

(slash)home(slash)fossee.

03:35 Let us navigate to (slash)home(slash)fossee using the file browser.
03:40 Open the sine.png file to see the plotted sine curve.
03:46 savefig can save the plot in many formats such as-

pdf - portable document format,

ps - post script,

03:57 eps - encapsulated post script, to be used with LaTeX documents,

svg - scalable vector graphics,

.png - portable network graphics .

04:10 Pause the video here, try out the following exercise and resume the video.
04:16 Save the sine plot in the eps format. Let us see the output for this exercise.
04:23 Type: savefig('slash home slash fossee slash sine.eps') and press Enter.
04:35 Now let us go to slash home slash fossee and see the new file created. We see the file sine.eps here.
04:48 Pause the video here, try out the following exercise and resume the video.

Save the sine plot in PDF, PS and SVG formats.

05:00 This brings us to the end of this tutorial. In this tutorial, we have learnt to:

1. Save plots using the savefig() function.

2. Save the plots in different formats like pdf, ps, png, svg and eps.

05:17 Here are some assignment questions for you to solve.

1. Which command is used to save a plot? saveplot(),

savefig(),

savefigure(),

saveplt()

2. savefig('sine.png') saves the plot in-

the root directory 'slash' (on GNU/Linux, Unix based systems), 'C:' (on windows),

05:40 will result in an error as full path is not supplied,

the current working directory,

predefined directory like “slash documents.”

05:50 And the answers are-

1. To save a plot, we use the savefig() function.

2. If we save a file without complete path, it gets saved in the current working directory.

06:02 Please post your timed questions in this forum.
06:07 Please post your general queries on Python in this forum.
06:12 FOSSEE team coordinates the TBC project.
06:16 Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India. For more details, visit this website.
06:25 This is Prabhu from IIT Bombay, signing off. Thank you.

Contributors and Content Editors

Pratik kamble, Sandhya.np14