Difference between revisions of "Python-3.4.3/C2/Saving-plots/English"
(Created page with "'''Python/C2/Saving-Plots/English''' '''Title of script''': '''Saving-Plots''' '''Author: Chandrika, Pravin, Vineeta Parmar, Thirumalesh H S''' '''Keywords: IPython, savef...") |
|||
Line 89: | Line 89: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| First, we will calculate the required points for the plot. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| First, we will calculate the required points for the plot. | ||
+ | To do this | ||
Type, | Type, | ||
− | '''x = linspace(-3*pi | + | '''x = linspace(-3*pi comma 3*pi comma 100) '''in the console. |
Line 105: | Line 106: | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Type '''plot(x | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| 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 147: | Line 148: | ||
− | It | + | It determines the format in which you want to save. |
|- | |- | ||
Line 172: | Line 173: | ||
− | + | Type '''savefig('slash home slash fossee slash sine.png')''' | |
− | + | ||
− | + | ||
− | Type '''savefig(' | + | |
Line 275: | Line 273: | ||
Save the '''sine''' '''plot''' in the '''eps''' '''format'''. | Save the '''sine''' '''plot''' in the '''eps''' '''format'''. | ||
− | + | Let us see the output for this exercise | |
− | + | ||
|- | |- | ||
Line 285: | Line 282: | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Type '''savefig(' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Type '''savefig('slash home slash fossee slash sine.eps')''' |
and press '''Enter.''' | and press '''Enter.''' |
Revision as of 13:21, 15 February 2017
Python/C2/Saving-Plots/English
Title of script: Saving-Plots
Author: Chandrika, Pravin, Vineeta Parmar, Thirumalesh H S
Keywords: IPython, savefig
|
|
Show Slide
“Saving Plots” |
Hello Friends. Welcome to the tutorial on "Saving Plots". |
Show Slide
|
At the end of this tutorial, you will be able to -
|
Show Slide
System Requirements |
To record this tutorial, I am using
|
Show Slide
Pre-requisites |
To practise this tutorial, you should know how to -
Use Plot Command Interactively
|
[Terminal]
ipython3
|
Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously.
|
[IPython console]
%pylab and press Enter. |
Let us initialise the pylab package
|
Show Slide
'Creating a basic plot'
|
Let us plot a sine curve from minus 3 pi to 3 pi. |
[IPython Terminal]
x = linspace(-3*pi, 3*pi, 100) |
First, we will calculate the required points for the plot.
To do this Type, x = linspace(-3*pi comma 3*pi comma 100) in the console.
|
[IPython Terminal]
|
Type plot(x comma sin(x)) in the console and press Enter.
Don't close the plot window for rest of the tutorial. |
[Plot Window] | As you can see we have made a very basic sine plot.
|
Show Slide
savefig()
|
For saving the plot, we will use the savefig() function.
Syntax: savefig(fname)
|
[IPython Terminal]
|
Type savefig('sine.png') and press Enter.
|
[IPython Terminal]
Type pwd and press Enter
|
To check current working directory,
|
[IPython Terminal]
|
To save the file in different directory,
|
Note that above file path is for Linux based file systems.
and sine.png is to be saved on Desktop
'C:\\Users\\fossee\\Desktop\\sine.png'
| |
[IPython Terminal]
|
Here we have used an extension dot png.
This will ensure that the image is saved as a PNG file.
|
[File browser]
|
We have saved the file to
(slash)home(slash)fossee,
|
[File browser]
|
Open the sine.png file to see the plotted sine curve. |
Show Slide
More on savefig()
|
savefig can save the plot in many formats, such as
ps - post script, eps - encapsulated post script, to be used with LaTeX documents svg - scalable vector graphics, png - portable network graphics |
Show Slide
Exercise 1
|
Pause the video here, try out the following exercise and resume the video.
Let us see the output for this exercise |
[Ipython Terminal]
savefig('/home/fossee/sine.eps')
|
Type savefig('slash home slash fossee slash sine.eps')
and press Enter.
|
[File Browser]
Highlight the file sine.eps for 2 seconds and then double click and open the file
|
Now let us go to /home/fossee and see the new file created.
|
Show Slide
Exercise 2
|
Pause the video here, try out the following exercise and resume the video.
PDF, PS and SVG formats. |
Show Slide
Summary slide
|
This brings us to the end of this tutorial. In this tutorial,we have learnt to,
- pdf - ps - png - svg - eps |
Show Slide
Assignment
|
Here are some assignment questions for you to solve
2. savefig('sine.png')saves the plot in,
|
Show Slide
Solutions
|
And the answers,
|
Show Slide
Forum |
Please post your timed queries in this forum. |
Show Slide
Fossee Forum |
Please post your general queries on Python in this forum. |
Show Slide
Textbook Companion |
FOSSEE team coordinates the TBC project. |
Show Slide
Acknowledgment |
Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
Previous slide | This is _________ from IIT Bombay (or FOSSEE, if you wish) signing off.
Thank you. |