Difference between revisions of "Python-3.4.3/C2/Plotting-Charts/English"
Line 122: | Line 122: | ||
| 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] | | 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 | + | 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: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. | ||
Line 139: | Line 139: | ||
− | we first need to load the data from the file using '''loadtxt''' command. Let us clear the terminal | + | we first need to load the data from the file using '''loadtxt''' command. Let us clear the terminal. |
Type | Type | ||
Line 147: | Line 147: | ||
− | '''unpack ''equal to'' True --> returns''' the '''transposed array '''of '''data''' | + | '''unpack ''equal to'' True --> returns''' the '''transposed array '''of '''data'''. |
|- | |- | ||
Line 162: | Line 162: | ||
− | Type '''pie(profit ''comma'' labels equal to year)''' and press '''Enter''' | + | Type '''pie(profit ''comma'' labels equal to year)''' and press '''Enter'''. |
Line 198: | Line 198: | ||
* '''yellow, magenta '''and''' blue'''. | * '''yellow, magenta '''and''' blue'''. | ||
− | Hint: In your '''ipython interpreter, '''try typing '''pie question mark''' | + | Hint: In your '''ipython interpreter, '''try typing '''pie question mark'''. |
|- | |- | ||
Line 214: | Line 214: | ||
− | Clear the '''plot window '''by typing '''clf open and close parentheses''' | + | Clear the '''plot window '''by typing '''clf open and close parentheses''' and press '''Enter'''. |
− | Type '''pie inside parentheses profit comma labels equal to year comma colors equal to inside parentheses color codes ''' | + | Type '''pie inside parentheses profit comma labels equal to year comma colors equal to inside parentheses the color codes ''' and press '''Enter'''. |
Line 248: | Line 248: | ||
'''bar ''inside parentheses'' x ''comma'' y''' | '''bar ''inside parentheses'' x ''comma'' y''' | ||
− | * '''x –''' a sequence of data | + | * where '''x –''' a sequence of data and |
* '''y '''- a sequence of data, the same length of x | * '''y '''- a sequence of data, the same length of x | ||
Line 284: | Line 284: | ||
− | Type '''bar '' | + | Type '''bar ''open and close parentheses'' year ''comma'' profit''' and press '''Enter'''. |
Line 299: | Line 299: | ||
− | <u>'''Hint'''</u>: Bar chart is not filled and which is '''hatched''' with 45<sup>o</sup> slanting lines | + | <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'''. | The data for the chart may be obtained from the file '''company-a-data.txt'''. | ||
Line 306: | Line 306: | ||
Hint: In your '''ipython interpreter, '''try typing '''bar ''question mark''''' | Hint: In your '''ipython interpreter, '''try typing '''bar ''question mark''''' | ||
− | + | ||
|- | |- | ||
Line 323: | Line 323: | ||
Clear the '''plot window '''by typing '''clf ''open and close parentheses''''' | Clear the '''plot window '''by typing '''clf ''open and close parentheses''''' | ||
− | Type '''bar '' | + | Type '''bar ''open and close parentheses'' year ''comma'' profit ''comma'' fill ''equal to'' False ''comma'' hatch ''equal to inside single quotes'' ''slanting line''''' and press '''Enter'''. |
Line 390: | Line 390: | ||
− | | 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 | + | | 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 answer is, |
− | # '''bar | + | # '''bar x ''comma'' y ''comma'' fill ''equal to'' False ''comma'' hatch ''is equal to'' a vertical line)''' is the correct option to generate a '''bar''' '''chart''' with vertical '''line''' '''hatching'''. |
Revision as of 12:25, 9 June 2017
Title of script: Plotting Charts
Author: Trupti Kini, 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 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. |
Open [Terminal] and type
ipython3
|
Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously.
Now, type ipython3 and press Enter. |
[IPython console]
type %pylab and press Enter. |
Let us initialize the pylab package.
Type %pylab and press Enter. |
Show Slide
Pie chart
|
A pie chart is a circular chart divided into sectors, to illustrate numerical proportion |
Show Slide
pie() function Syntax: pie(values, labels= labels)
|
The syntax for pie() function is as follows:
pie inside parentheses values comma labels equal to labels
|
Show Slide
Exercise 1 |
|
[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 open and close parentheses 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.
Plot a pie chart with the same data with the following colors for each wedges.
Hint: In your ipython interpreter, try typing pie question mark. |
[IPython Terminal]
|
Solution to Exercise 2
|
Show Slide
Bar chart
|
A bar chart is a chart
|
Show Slide
|
The syntax for bar chart is:
bar inside parentheses x comma y
|
Show Slide
Exercise 3
|
|
[IPython Terminal]
bar(year, profit)
|
Solution to Exercise 3
Type bar open and close parentheses year comma profit and press Enter.
|
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
Type bar open and close parentheses year comma profit comma fill equal to False comma hatch equal to inside single quotes slanting line and press Enter.
|
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 the following links 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 answer is,
|
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. |