Difference between revisions of "Python-3.4.3/C2/Plotting-Charts/English"
(Created page with "'''Python/C2/plotting-charts/English'''<div style="color:#000000;margin-left:0cm;margin-right:0cm;"></div><div style="margin-left:0cm;margin-right:0cm;"><span style="color:#00...") |
|||
Line 1: | Line 1: | ||
− | '''Python/C2/plotting-charts/English''' | + | '''Python/C2/plotting-charts/English''''''Title of script''': '''plotting charts''' |
− | + | '''Author: Anoop Jacob Thomas, Thirumalesh H S''' | |
− | + | '''Keywords: Python, IPython, pylab, scatter plot''', '''charts, matplotlib help''' | |
− | {| style="border-spacing:0 | + | {| style="border-spacing:0;" |
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| '''Visual Cue''' |
− | | '''Visual Cue''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| '''Narration''' |
− | | | + | |
− | + | ||
− | | | + | |
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show slide | ||
− | |||
− | |||
− | |||
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Hello friends. Welcome to the tutorial on '''plotting''' Narrator name is missing in the first slide | |
+ | Narrator name is missing in the first slide | ||
+ | Narrator name is missing in the first slide | ||
− | + | Narrator name is missing in the first slide | |
+ | Narrator name is missing in the first slide | ||
− | + | '''charts''' | |
− | + | ||
− | + | ||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show slide | ||
+ | Learning Objectives | ||
− | | | + | |
− | | Show slide | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| At the end of this tutorial, you will be able to - |
+ | |||
+ | |||
+ | * Create '''pie charts''' | ||
+ | * Create '''bar charts '''and | ||
+ | * Find more information on '''matplotlib''' | ||
+ | |||
+ | |||
+ | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show slide | ||
System Specifications | System Specifications | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To record this tutorial, I am using |
− | + | ||
− | + | ||
+ | * '''Ubuntu Linux 14.04''' operating system | ||
+ | * '''Python 3.4.3''' | ||
+ | * '''IPython 5.1.0''' | ||
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | |
− | | Show slide | + | |
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show slide | ||
Pre-requisites | Pre-requisites | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To practice this tutorial, you should know how to |
− | + | ||
− | + | ||
+ | * run basic '''Python''' '''commands''' on the '''ipython''' '''console''' | ||
+ | * '''Load data '''from''' '''files''' '''and | ||
+ | * '''Plot data'''. | ||
+ | If not, see the relevant Python tutorials on this website. | ||
− | |||
|- | |- | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [Terminal] |
'''ipython3''' | '''ipython3''' | ||
Line 61: | Line 75: | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top: | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0125in;padding-right:0.075in;"| Let us first open the '''Terminal '''by pressing '''Ctrl+Alt+T '''keys simultaneously. |
Now, type '''ipython3''' and press '''Enter'''. | Now, type '''ipython3''' and press '''Enter'''. | ||
− | |- style="background-color:#ffffff;border:1pt solid #000001;padding-top: | + | |
− | | [IPython console] | + | |- |
+ | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0125in;padding-right:0.075in;"| [IPython console] | ||
'''%pylab '''and press '''Enter.''' | '''%pylab '''and press '''Enter.''' | ||
− | | Let us initialise the '''pylab''' package. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0125in;padding-right:0.075in;"| Let us initialise the '''pylab''' package. |
Type '''%pylab '''and press''' Enter.''' | Type '''%pylab '''and press''' Enter.''' | ||
− | |||
− | |||
− | + | |- | |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
+ | '''Pie chart''' | ||
− | |||
− | |||
− | |||
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| A '''pie''' '''chart''' is a circular chart divided into sectors, change the text in slide | |
− | + | to illustrate numerical proportion | |
− | + | |- | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | |
+ | '''pie()''' function | ||
+ | Syntax: | ||
− | + | '''pie(values, labels= labels)''' | |
− | + | ||
+ | * '''values – '''the data to be plotted | ||
+ | * '''labels''' – the label for each wedge in the pie chart | ||
− | |||
− | |||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The syntax for pie() function is as follows: | ||
− | |||
− | |||
− | + | '''pie(values, labels= labels)''' | |
− | + | ||
+ | * '''values – '''the data to be plotted | ||
+ | * '''labels''' – the label for each wedge in the pie chart | ||
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
+ | |||
+ | Exercise 1 | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| * Plot a '''pie''' '''chart''' representing the profit percentage of company A. | ||
+ | * Use the data from file '''company-a-data.txt''' | ||
available in the code file link of this tutorial | available in the code file link of this tutorial | ||
Line 117: | Line 135: | ||
− | |||
− | |||
− | + | |- | |
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [File browser] |
+ | Open the '''file''' '''company-a-data.txt''' and show the content | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The data file has two columns with a set of values in each column. | ||
− | + | ||
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | The first line represents years. The second column represents the profit percentages. |
− | | | + | |
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [IPython Terminal] | ||
Line 133: | Line 153: | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To produce a scatter plot, |
− | + | we first need to load the data from the file using '''loadtxt''' command. | |
− | + | Type | |
− | + | '''year, profit = loadtxt('add/path/ company-a-data.txt', unpack = True)''' | |
− | + | '''unpack = True --> returns''' the '''transposed array '''of '''data''' | |
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | |
− | | | + | |- |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [Ipython Terminal] | ||
Line 155: | Line 176: | ||
− | | Type '''clf() '''to clear the plot window, if any plots executed previously. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Type '''clf() '''to clear the plot window, if any plots executed previously. |
Line 162: | Line 183: | ||
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | |
− | | [Plot Window] | + | |- |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [Plot Window] | ||
Show '''pie chart '''plot | Show '''pie chart '''plot | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Notice that we passed two arguments to the function '''pie()'''. |
− | + | First one being the '''values,''' which is '''profit''' in our case. | |
− | + | The next one being the set of '''labels''' to be used in the '''pie chart''', which is '''year''' in our case. | |
+ | |||
|- | |- | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide |
− | + | Exercise 2 | |
− | | style="border:0.5pt solid #000001;padding-top: | + | | style="border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Pause the video here, try out the following exercise and resume the video. |
− | + | interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" | |
+ | interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" | ||
− | + | interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" | |
− | + | ||
− | + | ||
+ | Plot a '''pie''' '''chart''' with the same data with the following colors for each wedges. | ||
− | + | * '''white, red, black, magenta,''' | |
+ | * '''yellow, blue, green, cyan,''' | ||
+ | * '''yellow, magenta '''and''' blue'''. | ||
− | + | Hint: In your '''ipython interpreter, '''try typing '''pie?''' | |
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | |
− | | | + | |- |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [IPython Terminal] | ||
Line 206: | Line 232: | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Solution to Exercise 2 |
Line 212: | Line 238: | ||
− | + | let us share and see the reply from Nirmala | |
− | + | let us share and see the reply from Nirmala | |
+ | let us share and see the reply from Nirmala | ||
− | + | let us share and see the reply from Nirmala | |
+ | let us share and see the reply from Nirmala | ||
− | + | let us share and see the reply from Nirmala | |
+ | let us share and see the reply from Nirmala | ||
− | + | Type '''pie(profit,labels=year,colors=('w','r','k','m','y','b','g','c','y','m','b')) ''' | |
− | + | This will display a pie chart with each wedge having the color as specified in the parameters. | |
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | + | '''Bar chart''' | |
− | + | ||
− | |||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| A '''bar chart''' is a '''chart''' | ||
− | + | * with rectangular bars | |
− | * | + | * with lengths proportional to the values that they represent. |
− | |||
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | |||
− | |||
− | + | '''bar()''' function | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The syntax for bar graph is: | |
+ | '''bar(x, y)''' | ||
− | + | * '''x –''' a sequence of data | |
− | + | * '''y '''- a sequence of data, the same length of x | |
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | + | Exercise 3 | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| * Plot a '''bar chart''' representing the profit percentage of company A. | |
+ | * Use the data from file '''company-a-data.txt'''. | ||
− | |- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top: | + | |
− | | | + | |
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [IPython Terminal] | ||
Line 279: | Line 311: | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Solution to Exercise 3 |
− | + | Clear the '''plot window '''by typing '''clf()''' | |
− | + | same as above | |
+ | Type '''bar(year, profit)''' | ||
− | |||
− | |||
− | |||
− | + | This will display a bar chart representing the profit percentage of company A | |
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
+ | Exercise 4 | ||
− | |||
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Plot a '''bar chart '''as shown in the image: | |
− | |||
+ | <u>'''Hint'''</u>: Bar chart is not filled and which is '''hatched''' with 45<sup>o</sup> slanting lines, | ||
− | + | The data for the chart may be obtained from the file '''company-a-data.txt'''. | |
− | + | Hint: In your '''ipython interpreter, '''try typing '''bar?''' | |
− | + | ||
− | + | ||
− | + | ||
+ | Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" | ||
+ | |||
+ | Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" | ||
+ | |||
+ | Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" | ||
+ | |||
+ | Clue is to try typing '''bar? '''In '''ipython interpreter.''' | ||
+ | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| '''['''Ipython Terminal''']''' | ||
+ | |||
+ | '''clf()''' | ||
Line 318: | Line 360: | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Solution to Exercise 4 |
− | + | Clear the '''plot window '''by typing '''clf()''' | |
− | + | same as above. Also mention the change in the output | |
+ | Type '''bar(year,profit,fill=False,hatch='/')''' | ||
− | |||
− | |||
− | |||
− | < | + | This will display a bar chart which is not filled and which is '''hatched''' with 45<sup>o</sup> slanting lines |
− | + | |- | |
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide |
− | + | "Getting help on matplotlib" | |
− | + | {SHOW WEBSITE while narrating} | |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Help about '''matplotlib''' can be obtained from '''matplotlib.sourceforge.net/contents.html''' | ||
− | + | More plots can be seen at | |
− | + | '''matplotlib.sourceforge.net/users/screenshots.html''' | |
+ | and also at '''matplotlib.sourceforge.net/gallery.html''' | ||
− | |||
− | |||
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
+ | Summary slide | ||
− | |||
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| This brings us to the end of this tutorial. | |
− | + | In this tutorial we learnt to, | |
− | + | ||
− | + | ||
− | + | * Plot a '''pie''' '''chart''' using '''pie()''' function | |
− | + | * Plot a '''bar''' '''chart''' using '''bar()''' function | |
+ | * Access the '''matplotlib '''online help | ||
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | + | Assignment | |
− | |||
− | |||
− | |||
− | |||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Here are some self assessment questions for you to solve. | ||
− | |||
− | |||
− | + | 1.What statement can be issued to generate a bar chart with vertical line hatching? | |
+ | * '''bar(x, y, color='w', hatch='/')''' | ||
+ | * '''bar(x, y, fill=False, hatch='//')''' | ||
+ | * '''bar(x, y, fill=False, hatch='|')''' | ||
+ | * '''bar(x, y, color='w', hatch='\''')''''' | ||
− | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | + | Solution to assignment | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| And the answers, | |
− | | | + | |
− | | | + | |
− | |||
− | |||
− | |||
− | |||
− | + | # '''bar(x, y, fill=False, hatch='|')''' is the correct option to generate a '''bar''' '''chart''' with vertical '''line''' '''hatching'''. | |
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | |- | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | |
− | + | Forum | |
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Please post your timed queries in this forum. |
− | | | + | |
− | + | ||
− | |||
|- | |- | ||
− | | | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide |
+ | Fossee Forum | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Please post your general queries on Python in this forum. | ||
− | + | |- | |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
− | + | Textbook Companion | |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| FOSSEE team coordinates the TBC project. | ||
+ | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Show Slide | ||
+ | |||
+ | Acknowledgment | ||
+ | |||
+ | http://spoken-tutorial.org | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. | ||
+ | |||
+ | For more details, visit this website. | ||
+ | |||
+ | |- | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Previous slide | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| This is _________ from IIT Bombay (or FOSSEE, if you wish) signing off. | ||
+ | |||
+ | Thank you. | ||
+ | |||
+ | |} |
Revision as of 15:51, 7 June 2017
'Python/C2/plotting-charts/English'Title of script: plotting charts
Author: Anoop Jacob Thomas, Thirumalesh H S
Keywords: Python, IPython, pylab, scatter plot, charts, matplotlib help
Visual Cue | Narration |
Show slide
|
Hello friends. Welcome to the tutorial on plotting Narrator name is missing in the first slide
Narrator name is missing in the first slide Narrator name is missing in the first slide Narrator name is missing in the first slide Narrator name is missing in the first slide charts |
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 |
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
Pie chart
|
A pie chart is a circular chart divided into sectors, change the text in slide
to illustrate numerical proportion |
Show Slide
pie() function Syntax: pie(values, labels= labels)
|
The syntax for pie() function is as follows:
|
Show Slide
Exercise 1 |
* Plot a pie chart representing the profit percentage of company A.
available in the code file link of this tutorial
|
[File browser]
Open the file company-a-data.txt and show the content |
The data file has two columns with a set of values in each column.
|
[IPython Terminal]
|
To produce a scatter plot,
Type
|
[Ipython Terminal]
pie(profit,labels=year)
|
Type clf() to clear the plot window, if any plots executed previously.
|
[Plot Window]
|
Notice that we passed two arguments to the function pie().
|
Show Slide
Exercise 2
|
Pause the video here, try out the following exercise and resume the video.
interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" interpreter - this word is at the end in the slide. Delete this. Give different color for "pie?" Plot a pie chart with the same data with the following colors for each wedges.
Hint: In your ipython interpreter, try typing pie? |
[IPython Terminal]
|
Solution to Exercise 2
let us share and see the reply from Nirmala let us share and see the reply from Nirmala let us share and see the reply from Nirmala let us share and see the reply from Nirmala let us share and see the reply from Nirmala let us share and see the reply from Nirmala let us share and see the reply from Nirmala Type pie(profit,labels=year,colors=('w','r','k','m','y','b','g','c','y','m','b'))
|
Show Slide
Bar chart
|
A bar chart is a chart
|
Show Slide
|
The syntax for bar graph is:
bar(x, y)
|
Show Slide
Exercise 3
|
* Plot a bar chart representing the profit percentage of company A.
|
[IPython Terminal]
bar(year, profit)
|
Solution to Exercise 3
same as above Type bar(year, profit)
|
Show Slide
Exercise 4
|
Plot a bar chart as shown in the image:
The data for the chart may be obtained from the file company-a-data.txt.
Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" Hint: In ipython interpreter, try typing bar? change the slide. Give different color for the command "bar?" Clue is to try typing bar? In ipython interpreter. |
[Ipython Terminal]
clf()
|
Solution to Exercise 4
same as above. Also mention the change in the output Type bar(year,profit,fill=False,hatch='/')
|
Show Slide
"Getting help on matplotlib" {SHOW WEBSITE while narrating} |
Help about matplotlib can be obtained from matplotlib.sourceforge.net/contents.html
More plots can be seen at matplotlib.sourceforge.net/users/screenshots.html and also at matplotlib.sourceforge.net/gallery.html
|
Show Slide
Summary slide
|
This brings us to the end of this tutorial.
|
Show Slide
Assignment
|
Here are some self assessment questions for you to solve.
|
Show Slide
Solution to assignment
|
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. |