<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC2%2FSaving-plots%2FEnglish</id>
		<title>Python/C2/Saving-plots/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC2%2FSaving-plots%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C2/Saving-plots/English&amp;action=history"/>
		<updated>2026-05-13T01:59:49Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python/C2/Saving-plots/English&amp;diff=930&amp;oldid=prev</id>
		<title>Pravin1389: moved Python/C2/Saving-plots /English to Python/C2/Saving-plots/English</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C2/Saving-plots/English&amp;diff=930&amp;oldid=prev"/>
				<updated>2012-12-02T06:28:44Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php/Python/C2/Saving-plots_/English&quot; class=&quot;mw-redirect&quot; title=&quot;Python/C2/Saving-plots /English&quot;&gt;Python/C2/Saving-plots /English&lt;/a&gt; to &lt;a href=&quot;/index.php/Python/C2/Saving-plots/English&quot; title=&quot;Python/C2/Saving-plots/English&quot;&gt;Python/C2/Saving-plots/English&lt;/a&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 06:28, 2 December 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Pravin1389</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python/C2/Saving-plots/English&amp;diff=445&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{| border=1 !Visual Cue !Narration |- | Show Slide 1   containing title, name of the production team along with the logo of MHRD  | Hello and welcome to the tutorial on &quot;Saving p…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C2/Saving-plots/English&amp;diff=445&amp;oldid=prev"/>
				<updated>2012-11-29T05:54:58Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Visual Cue !Narration |- | Show Slide 1   containing title, name of the production team along with the logo of MHRD  | Hello and welcome to the tutorial on &amp;quot;Saving p…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Visual Cue&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 1 &lt;br /&gt;
&lt;br /&gt;
containing title, name of the production team along with the logo of MHRD &lt;br /&gt;
| Hello and welcome to the tutorial on &amp;quot;Saving plots&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 2 &lt;br /&gt;
&lt;br /&gt;
Learning objectives &lt;br /&gt;
| At the end of this tutorial, you will be able to,&lt;br /&gt;
&lt;br /&gt;
# Save plots using &amp;lt;tt&amp;gt;savefig()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# Save plots in different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 3 &lt;br /&gt;
&lt;br /&gt;
Pre-requisite &lt;br /&gt;
&lt;br /&gt;
Shift to terminal and start ipython -pylab &lt;br /&gt;
&lt;br /&gt;
 ipython -pylab&lt;br /&gt;
| Before beginning this tutorial,we would suggest you to complete the tutorial on &amp;quot;Using plot interactively&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;Start your IPython interpreter with the command ipython -pylab &amp;lt;Pause&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you know, it will start your IPython interpreter with the required python modules for plotting and saving your plots.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 4&lt;br /&gt;
&lt;br /&gt;
'Creating a basic plot' &lt;br /&gt;
| To start with, let us plot a sine wave from minus 3 pi to 3 pi. Let us start by calculating the required points for the plot. It can be done using linspace as,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  x = linspace(-3*pi,3*pi,100)&lt;br /&gt;
| We have stored the required points in x. Now let us plot the points using the plot statement.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  plot(x,sin(x))&lt;br /&gt;
&lt;br /&gt;
Keep the plot open &lt;br /&gt;
| 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.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 5&lt;br /&gt;
&lt;br /&gt;
savefig() &lt;br /&gt;
| For saving the plot, we will use &amp;lt;tt&amp;gt;savefig()&amp;lt;/tt&amp;gt; function. For this we shall keep the plot window open alongside the terminal. The statement is,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch the focus to IPython interpreter window &lt;br /&gt;
&lt;br /&gt;
 savefig('/home/fossee/sine.png')&lt;br /&gt;
| Notice that &amp;lt;tt&amp;gt;savefig&amp;lt;/tt&amp;gt; function takes one argument which is the filename. The last 3 characters after the &amp;lt;tt&amp;gt;.&amp;lt;/tt&amp;gt; in the filename is the extension or type of the file which determines the format in which you want to save.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Highlight the /home/fossee part using mouse movements &lt;br /&gt;
| Also, note that we gave the full path or the absolute path to which we want to save the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Highlight the .png part using mouse movements &lt;br /&gt;
| Here we have used an extension &amp;lt;tt&amp;gt;.png&amp;lt;/tt&amp;gt; which means we want to save the image as a PNG file.&lt;br /&gt;
&lt;br /&gt;
Now let us locate the file &amp;lt;tt&amp;gt;sine.png&amp;lt;/tt&amp;gt; which we had saved a while ago. We have saved the file to &amp;lt;tt&amp;gt;/home/fossee&amp;lt;/tt&amp;gt; so let us navigate to &amp;lt;tt&amp;gt;/home/fossee&amp;lt;/tt&amp;gt; using thefile browser.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Open the browser, navigate to /home/fossee and highlight the file sine.png &lt;br /&gt;
| Yes, the file &amp;lt;tt&amp;gt;sine.png&amp;lt;/tt&amp;gt; is here. Let us open it and check.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Open the file sine.png and show it for two-three seconds and then close it and return to IPython interpreter, make sure the plot window is still open, also don't close the file browser window &lt;br /&gt;
&lt;br /&gt;
switch to next slide, More on savefig() &lt;br /&gt;
| So in-order to save a plot, we use &amp;lt;tt&amp;gt;savefig&amp;lt;/tt&amp;gt; function. &amp;lt;tt&amp;gt;savefig&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 6 &lt;br /&gt;
&lt;br /&gt;
Assignment 1 &lt;br /&gt;
| Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
Save the sine plot in the EPS format which can be embedded in LaTeX documents.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch focus to the already open plot window &lt;br /&gt;
| We still have the sine plot with us,let us now save the plot as &amp;lt;tt&amp;gt;sine.eps&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch focus to IPython interpreter &lt;br /&gt;
| Now, We will save the plot using the function &amp;lt;tt&amp;gt;savefig&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  savefig('/home/fossee/sine.eps')&lt;br /&gt;
&lt;br /&gt;
Switch focus to file browser window &lt;br /&gt;
| Now let us go to &amp;lt;tt&amp;gt;/home/fossee&amp;lt;/tt&amp;gt; and see the new file created.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Highlight the file sine.eps for 2 seconds and'''&lt;br /&gt;
&lt;br /&gt;
then double click and open the file &lt;br /&gt;
| Yes! the new file &amp;lt;tt&amp;gt;sine.eps&amp;lt;/tt&amp;gt; is here.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 7 &lt;br /&gt;
&lt;br /&gt;
Assignment 2 &lt;br /&gt;
| Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
Save the sine plot in PDF, PS and SVG formats.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 8 &lt;br /&gt;
&lt;br /&gt;
Summary slide &lt;br /&gt;
| This brings us to the end of this tutorial. In this tutorial,we have learnt to,&lt;br /&gt;
&lt;br /&gt;
# Save plots using the &amp;lt;tt&amp;gt;savefig()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# Save the plots in different formats like - pdf - ps - png - svg - eps&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 9&lt;br /&gt;
&lt;br /&gt;
Self assessment questions slide&lt;br /&gt;
| Here are some self assessment questions for you to solve&lt;br /&gt;
&lt;br /&gt;
# Which command is used to save a plot.&lt;br /&gt;
** saveplot()&lt;br /&gt;
** savefig()&lt;br /&gt;
** savefigure()&lt;br /&gt;
** saveplt()&lt;br /&gt;
# &amp;lt;tt&amp;gt;savefig('sine.png')&amp;lt;/tt&amp;gt; saves the plot in,&lt;br /&gt;
** The root directory &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; (on GNU/Linux, Unix based systems), &amp;lt;tt&amp;gt;c:\&amp;lt;/tt&amp;gt; (on windows).&lt;br /&gt;
** Will result in an error as full path is not supplied.&lt;br /&gt;
** The current working directory.&lt;br /&gt;
** Predefined directory like &amp;lt;tt&amp;gt;/documents&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 10 &lt;br /&gt;
&lt;br /&gt;
Solution of self assessment questions on slide &lt;br /&gt;
| And the answers,&lt;br /&gt;
&lt;br /&gt;
# To save a plot,we use the &amp;lt;tt&amp;gt;savefig()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# Whenever we save a file,it gets saved in the current working directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 11 &lt;br /&gt;
&lt;br /&gt;
Acknowledgment slide &lt;br /&gt;
| Hope you have enjoyed and found it useful. Thank you!&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>