Python-3.4.3/C2/Plotting-Charts/English
Visual Cue | Narration |
Show slide
|
Hello friends. Welcome to the tutorial on plotting Narrator name is missing in the first slideOk..We will write the narrator name once it is fixed. The previous tutorial had March date hence I did not write april's dateyou can write the current date when the script is completed.Change the date to Aprilcharts |
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 * Ubuntu Linux 14.04 operating system
|
Show slide
Pre-requisites |
To practice this tutorial, you should know how to * run basic Python commands on the ipython console
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 slideto illustrate numerical proportion |
Show Slide
pie() function Syntax:
pie(values, labels= labels) * values – the data to be plotted
|
The syntax for pie() function is as follows:
values – the data to be plotted
|
Show Slide
Exercise 1
|
* 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
|
[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.
The first line represents years. The second column represents the profit percentages.
|
[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?"Black is missing in the slidechange the slidePlot 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
"Plot a pie chart with the data with colors for each wedges as white, red, black, "
This will display a pie chart with each wedge having the color as specified in the parameters.
|
Show Slide
Bar chart
|
A bar chart is a chart* with rectangular bars
|
Show Slide
|
The syntax for bar graph is:
bar(x, y) * x – a sequence of data
|
Show Slide
Exercise 3
|
* Plot a bar chart representing the profit percentage of company A.
|
[IPython Terminal]
bar(year, profit)
|
Solution to Exercise 3
This will display a bar chart representing the profit percentage of company A
|
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.
|
[Ipython Terminal]
clf()
|
Solution to Exercise 4
|
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.
In this tutorial we learnt to,
|
Show Slide
Assignment
|
Here are some self assessment questions for you to solve.
bar(x, y, color='w', hatch='/')
|
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.
|