Difference between revisions of "Python-3.4.3/C2/Subplots/English"
(Created page with ": '''Python/C2/Subplots/English''' '''Title of script''': '''Subplots''' '''Author: Aditya Palaparthy''' '''Keywords: Python, IPython,''' '''plot, subplot''' {| style="bo...") |
|||
Line 108: | Line 108: | ||
Type | Type | ||
− | '''x | + | '''x equals to linspace inside brackets 0 comma 50 comma 500 '''and press enter |
− | '''plot | + | '''plot inside brackets x comma cos(x).''' |
− | '''y | + | '''y equals to linspace inside brackets 0 comma 5 comma 100.''' |
''' ''' | ''' ''' | ||
− | '''plot | + | '''plot inside brackets y comma y square.''' |
Line 158: | Line 158: | ||
'''clf()''' | '''clf()''' | ||
− | '''subplot | + | '''subplot inside the brackets 2 comma 1 comma 1''' |
Line 195: | Line 195: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| If we execute the '''subplot command''' as | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| If we execute the '''subplot command''' as | ||
− | '''subplot | + | '''subplot inside the brackets 2 comma 1 comma 2''' |
The '''lower subplot''' is created. | The '''lower subplot''' is created. | ||
Line 225: | Line 225: | ||
Type | Type | ||
− | '''subplot | + | '''subplot inside brackets 2 comma 1 comma 1''' |
− | '''plot | + | '''plot inside brackets x, cos(x)''' |
− | '''subplot | + | '''subplot inside brackets 2 comma 1 comma 2 ''' |
− | '''plot | + | '''plot inside brackets y comma y square''' |
|- | |- | ||
Line 252: | Line 252: | ||
'''clf()''' | '''clf()''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now clear the plot window |
|- | |- | ||
Line 290: | Line 290: | ||
'''v = linspace(21, 100, 500)''' | '''v = linspace(21, 100, 500)''' | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To start with, we have been given the '''range''' of '''Volume''' using which we can define the variable '''v.''' | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To start with, we have been given the '''range''' of '''Volume''' using which we can define the variable '''v.''' | ||
+ | |||
+ | '''v equals to linspace inside brackets 21 comma 100 comma 500''' | ||
|- | |- | ||
Line 301: | Line 303: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| We can create first '''subplot''' and draw '''Pressure''' v/s '''Volume''' '''graph '''using this '''v'''. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| We can create first '''subplot''' and draw '''Pressure''' v/s '''Volume''' '''graph '''using this '''v'''. | ||
+ | |||
+ | '''subplot(2, 1, 1) ''' | ||
+ | |||
+ | '''plot(v, 2.0 by v)''' | ||
Line 315: | Line 321: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now we can create the second '''subplot''' and draw the '''Pressure''' v/s '''Temperature plot''' as follows | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now we can create the second '''subplot''' and draw the '''Pressure''' v/s '''Temperature plot''' as follows | ||
+ | |||
+ | |||
+ | '''subplot(2 comma 1 comma 2)''' | ||
+ | |||
+ | '''plot(200 comma 2.0 divided by v)''' | ||
|- | |- | ||
Line 327: | Line 338: | ||
So we will create same number of '''points''' for '''temperature.''' | So we will create same number of '''points''' for '''temperature.''' | ||
+ | |||
+ | Type | ||
+ | |||
+ | '''t = linspace inside brackets 200 comma 200 comma 500. ''' | ||
|- | |- | ||
Line 337: | Line 352: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now, we have 500 values in '''t '''and''' '''each with the value 200 '''Kelvin'''. '''Plotting''' this data, we get the required '''plot. ''' | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now, we have 500 values in '''t '''and''' '''each with the value 200 '''Kelvin'''. '''Plotting''' this data, we get the required '''plot. ''' | ||
+ | |||
+ | Type | ||
+ | |||
+ | '''plot inside brackets t comma 2.0 divided by v''' | ||
|- | |- |
Revision as of 15:53, 15 February 2017
- Python/C2/Subplots/English
Title of script: Subplots
Author: Aditya Palaparthy
Keywords: Python, IPython, plot, subplot
|
|
Show Slide
containing title, name of the production team along with the logo of MHRD
|
Hello Friends. Welcome to the spoken tutorial on "Subplots".
|
Show Slide
Objectives
|
At the end of this tutorial, you will be able to,
|
Show Slide
System Specifications |
To record this tutorial, I am using
|
Show Slide
Pre-requisites |
To practise this tutorial, you should know how to
If not, see the pre-requisite Python tutorials on this website. |
[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
|
[IPython Terminal] x = linspace(0, 50, 500) plot(x, cos(x)) y = linspace(0, 5, 100) plot(y, y ** 2)
|
To compare two plots we draw the plots in the same plotting area.
x equals to linspace inside brackets 0 comma 50 comma 500 and press enter plot inside brackets x comma cos(x). y equals to linspace inside brackets 0 comma 5 comma 100.
plot inside brackets y comma y square.
|
[Plot Window]
|
Here the two plots have different regular axes so we cannot draw overlaid plots.
|
[IPython Terminal]
subplot(2, 1, 1)
|
In such cases we can draw subplots.
Type clf() subplot inside the brackets 2 comma 1 comma 1
|
[Plot Window] | We can see the first subplot. |
Pause for a while | The subplot command takes three arguments.
Here the first argument is 2, to split the plot horizontally.
|
[IPython Terminal]
|
If we execute the subplot command as
subplot inside the brackets 2 comma 1 comma 2 The lower subplot is created. |
[Plot Window] | Here, we can see two subplots. |
[IPython Terminal]
x = linspace(0, 50, 500) subplot(2, 1, 1) plot(x, cos(x)) y = linspace(0, 5, 100) subplot(2, 1, 2) plot(y, y ** 2)
|
Now we can draw plots in each of the subplot area using the plot command.
subplot inside brackets 2 comma 1 comma 1 plot inside brackets x, cos(x) subplot inside brackets 2 comma 1 comma 2 plot inside brackets y comma y square |
[Plot window] | This created two plots one in each of the subplot area.
For the cosine curve x-axis varies from 0 to 50 and y-axis varies from -1 to 1. For the parabolic curve x-axis varies from 0 to 5 and y-axis varies from 0 to 25. |
[IPython Terminal]
|
Now clear the plot window |
Show Slide
Exercise 1
|
Pause the video. Try this exercise and then resume the video
Assume nR =0.01 Joules/Kelvin and T = 200K. V can be in the range from 21cc to 100cc.
|
Switch to the terminal for the solution. | |
[IPython Terminal]
v = linspace(21, 100, 500) |
To start with, we have been given the range of Volume using which we can define the variable v.
v equals to linspace inside brackets 21 comma 100 comma 500 |
[IPython Terminal]
subplot(2, 1, 1) plot(v, 2.0/v)
|
We can create first subplot and draw Pressure v/s Volume graph using this v.
subplot(2, 1, 1) plot(v, 2.0 by v)
|
[IPython Terminal]
subplot(2, 1, 2) plot(200, 2.0/v)
|
Now we can create the second subplot and draw the Pressure v/s Temperature plot as follows
plot(200 comma 2.0 divided by v) |
[IPython Terminal]
t = linspace(200, 200, 500)
|
We have an error now, telling x and y dimensions don't match.
Type t = linspace inside brackets 200 comma 200 comma 500. |
[IPython Terminal]
|
Now, we have 500 values in t and each with the value 200 Kelvin. Plotting this data, we get the required plot.
Type plot inside brackets t comma 2.0 divided by v |
[Plot Window] | We can see two subplots of Pressure v/s Volume and Pressure v/s Temperature respectively. |
Show Slide
Summary slide
|
This brings us to the end of this tutorial. In this tutorial, we have learnt to,
|
Show Slide
Evaluation
|
Here are some self assessment questions for you to solve
|
Show Slide
Solutions
|
And the answer is, first option.
|
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
Acknowledgement |
Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
Show Slide
Thank You |
This is _________ from IIT Bombay signing off.
Thank You |