Difference between revisions of "Python-3.4.3/C2/Other-Types-Of-Plots/English"
Pratham920 (Talk | contribs) (Created page with "'''lPython/C2/Other-types-of-plots/English''''''Title of script''': '''Other types of plots. ''' '''Author: Anoop Jacob Thomas, Thirumalesh H S''' '''Keywords: Python, IPyth...") |
Pratham920 (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | '''lPython/C2/Other-types-of-plots/English''''''Title of script''': '''Other types of plots. ''' | + | '''lPython/C2/Other-types-of-plots/English''' |
+ | |||
+ | |||
+ | '''Title of script''': '''Other types of plots. ''' | ||
'''Author: Anoop Jacob Thomas, Thirumalesh H S''' | '''Author: Anoop Jacob Thomas, Thirumalesh H S''' | ||
Line 86: | Line 89: | ||
− | Type ''' | + | Type ''percent '''''pylab '''and press''' Enter.''' |
|- | |- | ||
Line 104: | Line 107: | ||
Exercise 1 | Exercise 1 | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| * Plot a '''scatter''' '''plot''' showing the percentage profit of a company A from the year 2000 | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| * Plot a '''scatter''' '''plot''' showing the percentage profit of a company A from the year 2000 to 2010. |
− | * The data for the same is available in the '''file''' '''company | + | * The data for the same is available in the '''file''' '''company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt'''. |
− | * '''company | + | * '''company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt''' file is available in the code file link of this tutorial. |
* Please download and use it. | * Please download and use it. | ||
Line 118: | Line 121: | ||
cat '''company-a-data.txt''' | cat '''company-a-data.txt''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Let us see the content of the file '''company | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Let us see the content of the file '''company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt'''. |
+ | So type, | ||
− | '''cat company | + | '''cat company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt'''.''' '''and''' press Enter''' |
|- | |- | ||
Line 128: | Line 132: | ||
− | The column | + | The first column represents the years. And the second column represents the profit percentage. |
|- | |- | ||
Line 146: | Line 150: | ||
− | '''year '''''comma''''' profit '''''equal to''''' loadtxt '''''within parentheses within single quotes '''''company | + | '''year '''''comma''''' profit '''''equal to''''' loadtxt '''''within parentheses within single quotes '''''company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt '''''after single quotes comma''''' unpack '''''comma''''' True '''and''' Press Enter''' |
Line 168: | Line 172: | ||
* '''x '''is''' '''a sequence of data | * '''x '''is''' '''a sequence of data | ||
− | * '''y '''is''' '''a sequence of data having same length of '''x''' | + | * '''y '''is''' '''a sequence of data having the same length of '''x''' |
Line 177: | Line 181: | ||
'''scatter(year, profit)''' | '''scatter(year, profit)''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Let us use '''scatter | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Let us use '''scatter function '''to '''plot scatter graph '''for data stored in '''year '''and''' profit. ''' |
Line 185: | Line 189: | ||
Notice that we passed two arguments to '''scatter() '''function. | Notice that we passed two arguments to '''scatter() '''function. | ||
− | First one being the values in x-coordinate | + | First one being the values in x-coordinate that is '''year.''' |
Line 200: | Line 204: | ||
− | '''Plot''' a scatter plot of same data in '''company | + | '''Plot''' a scatter plot of same data in '''company '''''hyphen '''''a '''''hyphen '''''data '''''dot '''''txt''' with red diamond markers. |
Line 265: | Line 269: | ||
Exercise 3 | Exercise 3 | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Plot a '''log-log''''' '''''chart''' of '''y '''''equal to''''' 5 times x | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Plot a '''log-log''''' '''''chart''' of '''y '''''equal to''''' 5 times x cube''' for '''x''' from 1 to 20. |
|- | |- | ||
Line 282: | Line 286: | ||
Type''' ''' | Type''' ''' | ||
− | '''x | + | '''x '''''equalto '''''linspace '''''within parentheses''''' 1 '''''comma '''''20 '''''comma '''''100 '''and''' press Enter''' |
− | '''y '''''equal to '''''5 '''''into''''' x '''''raised to''''' 3''' and''' press Enter''' | + | Then''', y '''''equal to '''''5 '''''into''''' x '''''raised to''''' 3''' and''' press Enter''' |
|- | |- | ||
Line 333: | Line 337: | ||
and '''plot '''''within parentheses '''''x '''''comma''''' y '''''comma''''' color '''''equal to within single quotes '''''b '''''comma''''' marker '''''equal to within single quotes '''''d'''does exactly the same.? | and '''plot '''''within parentheses '''''x '''''comma''''' y '''''comma''''' color '''''equal to within single quotes '''''b '''''comma''''' marker '''''equal to within single quotes '''''d'''does exactly the same.? | ||
− | * True | + | * True or False |
− | + | ||
Line 345: | Line 348: | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| And the | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| And the answer, |
# '''False'''. Both functions do not produce the same kind of plot. | # '''False'''. Both functions do not produce the same kind of plot. |
Revision as of 17:39, 5 September 2017
lPython/C2/Other-types-of-plots/English
Title of script: Other types of plots.
Author: Anoop Jacob Thomas, Thirumalesh H S
Keywords: Python, IPython, pylab, scatter plot, loglog plot, video tutorial
Visual Cue | Narration |
Show slide
|
Hello friends. Welcome to the tutorial on Other types of plots |
Show slide
Learning 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
If not, see the relevant Python tutorials on http://spoken-tutorial.org
|
To practice this tutorial, you should know how to
If not, see the relevant 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.
|
Show Slide
Scatter plot |
In a scatter plot, the data is displayed as a collection of points.
|
Show Slide
Exercise 1 |
* Plot a scatter plot showing the percentage profit of a company A from the year 2000 to 2010.
|
In terminal type:
cat company-a-data.txt |
Let us see the content of the file company hyphen a hyphen data dot txt.
So type, cat company hyphen a hyphen data dot txt. and press Enter |
Show cat company-a-data.txt output | The data file has two columns with a set of values in each column.
|
[IPython Terminal]
|
To produce the scatter plot,
Type
|
Highlight unpack = True | unpack equal to True returns the transposed array of data |
Show Slide
scatter() function
|
scatter() function is used to generate the scatter graph
|
[IPython Terminal]
|
Let us use scatter function to plot scatter graph for data stored in year and profit.
First one being the values in x-coordinate that is year.
|
Show Slide
Exercise |
Pause the video here, try out the following exercise and resume the video.
|
[IPython Terminal]
scatter(year,profit,color='r',marker='d')
|
Solution to Exercise
scatter within parentheses year comma profit comma color equal to within single quotes r comma marker equal to within single quotes d and press Enter |
Show plot window | Thus, we got our scatter plot.
|
Show Slide
log-log graph
|
* A log-log plot is a two-dimensional graph of numerical data.
|
Show Slide
loglog() function
|
Syntax
loglog within parentheses x comma y
|
Show Slide
Exercise 3 |
Plot a log-log chart of y equal to 5 times x cube for x from 1 to 20. |
[IPython Terminal]
y = 5*x**3
|
Before we actually plot, let us calculate the points needed for that.
x equalto linspace within parentheses 1 comma 20 comma 100 and press Enter Then, y equal to 5 into x raised to 3 and press Enter |
[IPython Terminal]
clf() loglog(x,y)
|
Clear the plot window by typing clf parentheses and press Enter
|
Show plot window | We see the required plot |
Show Slide
Summary
|
This brings us to the end of this tutorial. In this tutorial we learnt to,
|
Show Slide
Assignment
|
Here are some self assessment questions for you to solve.
and plot within parentheses x comma y comma color equal to within single quotes b comma marker equal to within single quotes ddoes exactly the same.?
|
Show Slide
Solution to assignment
|
And the answer,
|
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. |