other-type-of-plots/script.rst
author anand
Mon, 15 Nov 2010 14:31:42 +0530
changeset 498 4255f995a40c
parent 472 fcdec2d28c9a
permissions -rw-r--r--
checklist not OK; one more long answer question has to be included.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     1
.. Objectives
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     2
.. ----------
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     3
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     4
.. At the end of this tutorial, you will be able to 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     5
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     6
.. 1. Create scatter plot
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     7
.. #. Create pie charts
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     8
.. #. Create bar charts
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
     9
.. #. Create log-log plots.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    10
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    11
.. Prerequisites
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    12
.. -------------
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    13
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    14
..   1. should have ``ipython`` and ``pylab`` installed. 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    15
..   #. getting started with ``ipython``.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    16
..   #. loading data from files
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    17
..   #. plotting the data
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    18
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    19
     
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    20
.. Author              : Anoop Jacob Thomas <anoop@fossee.in>
369
8988867e0470 made changes to other type of plots script after internal review.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 354
diff changeset
    21
   Internal Reviewer   : Puneeth
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    22
   External Reviewer   :
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    23
   Language Reviewer   : Bhanukiran
472
fcdec2d28c9a Checklist OK for `The other kinds of plots`
anand
parents: 471
diff changeset
    24
   Checklist OK?       : <10-11-2010, Anand, OK> [2010-10-05]
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    25
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    26
.. #[Puneeth: Quickref missing]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    27
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    28
===================
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    29
Other type of plots
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    30
===================
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    31
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    32
{{{ show the first slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    33
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    34
Hello and welcome to the tutorial ``The other kinds of plots``.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    35
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    36
.. #[Puneeth: this sentence doesn't read well]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    37
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    38
{{{ show the outline slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    39
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    40
.. #[Puneeth: motivate looking at other plots. Why are we looking at
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    41
.. them? Tell that we have only looked at one type of plot all the
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    42
.. while, etc.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    43
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    44
Till now we have seen only one kind of plotting, and in this tutorial we
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    45
are going to see more kinds of plots such as the scatter plot, the pie chart, the bar chart and
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    46
the log-log plot. This tutorial covers the making of other kinds of
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    47
plots and also gives an introduction to matplotlib help.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    48
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    49
.. #[Puneeth: cover, see and introduce you. be consistent. does, the
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    50
.. "We" include the viewer or not?]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    51
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    52
Let us start with scatter plot. 
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    53
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    54
{{{ switch to the next slide, scatter plot }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    55
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    56
In a scatter plot, the data is displayed as a collection of points,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    57
each having the value of one variable determining the position on the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    58
horizontal axis and the value of the other variable determining the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    59
position on the vertical axis. This kind of plot is also called a
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    60
scatter chart, a scatter diagram or a scatter graph.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    61
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    62
Before we proceed further, start your IPython interpreter
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    63
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    64
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    65
    ipython -pylab
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    66
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    67
{{{ open the ipython interpreter in the terminal using the command
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    68
ipython -pylab }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    69
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    70
{{{ switch to the next slide having the problem statement of first
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    71
exercise }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    72
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    73
Now, let us plot a scatter plot showing the percentage profit of
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    74
a company A from the year 2000-2010. The data for the same is available
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    75
in the file ``company-a-data.txt``.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    76
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    77
{{{ open the file company-a-data.txt and show the content }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    78
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    79
The data file has two lines with a set of values in each line, the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    80
first line representing years and the second line representing the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    81
profit percentages.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    82
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    83
{{{ close the file and switch to the terminal }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    84
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
    85
To produce the scatter plot, we first need to load the data from the
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    86
file using ``loadtxt``. We learned it in one of the previous sessions,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    87
and it can be done as ::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    88
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    89
    year,profit =
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    90
    loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    91
369
8988867e0470 made changes to other type of plots script after internal review.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 354
diff changeset
    92
By default loadtxt converts the value to float. The
8988867e0470 made changes to other type of plots script after internal review.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 354
diff changeset
    93
``dtype=type(int())`` argument in loadtxt converts the value to
8988867e0470 made changes to other type of plots script after internal review.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 354
diff changeset
    94
integer as we require the data as integer further in the tutorial.
8988867e0470 made changes to other type of plots script after internal review.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 354
diff changeset
    95
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    96
.. #[Puneeth: make a remark about dtype, that has not been covered in
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    97
.. the loadtxt tutorial.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    98
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    99
{{{ switch to next slide, ``scatter`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   100
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   101
Now in-order to generate the scatter graph we will use the function 
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   102
``scatter()`` 
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   103
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   104
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   105
	scatter(year,profit)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   106
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   107
Notice that we passed two arguments to ``scatter()`` function, first
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   108
one the values in x-coordinate, year, and the other the values in
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   109
y-coordinate, the profit percentage.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   110
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   111
{{{ switch to the next slide which has the problem statement of
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   112
problem to be tried out }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   113
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   114
Now here is a question for you to try out, plot the same data with red
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   115
diamonds markers. 
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   116
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   117
.. **Clue** - *try scatter? in your ipython interpreter* 
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   118
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   119
Pause here and solve the question before moving on.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   120
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   121
.. scatter(year,profit,color='r',marker='d')
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   122
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
   123
Now let us see another kind of plot, the pie chart, for the same data.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   124
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   125
.. #[Puneeth: instead of just saying that, say that let's plot a pie
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   126
.. chart for the same data. continuity, will be good.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   127
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   128
{{{ switch to the slide which says about pie chart }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   129
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   130
A pie chart or a circle graph is a circular chart divided into
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   131
sectors, illustrating proportion.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   132
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   133
{{{ switch to the slide showing the problem statement of second
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   134
exercise question }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   135
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   136
Plot a pie chart representing the profit percentage of company A, with
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   137
the same data from file ``company-a-data.txt``. So let us reuse the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   138
data we have loaded from the file previously.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   139
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   140
.. #[Puneeth, this part can be move above.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   141
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   142
{{{ switch to next slide, ``pie()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   143
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   144
We can plot the pie chart using the function ``pie()``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   145
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   146
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   147
   pie(profit,labels=year)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   148
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   149
Notice that we passed two arguments to the function ``pie()``. First
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   150
one the values and the next one the set of labels to be used in the
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   151
pie chart.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   152
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   153
{{{ switch to the next slide which has the problem statement of
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   154
problem to be tried out }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   155
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   156
Now here is a question for you to try out, plot a pie chart with the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   157
same data with colors for each wedges as white, red, black, magenta,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   158
yellow, blue, green, cyan, yellow, magenta and blue respectively.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   159
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   160
.. **Clue** - *try pie? in your ipython interpreter* 
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   161
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   162
Pause here and solve the question before moving on.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   163
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   164
.. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b'))
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   165
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   166
{{{ switch to the slide which says about bar chart }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   167
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
   168
Now let us move on to the bar charts. A bar chart or bar graph is a chart
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   169
with rectangular bars with lengths proportional to the values that
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   170
they represent.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   171
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   172
{{{ switch to the slide showing the problem statement of fifth
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   173
exercise question }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   174
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   175
Plot a bar chart representing the profit percentage of company A, with
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   176
the same data from file ``company-a-data.txt``. 
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   177
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   178
So let us reuse the data we have loaded from the file previously.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   179
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   180
{{{ switch to the next slide, ``bar()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   181
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   182
We can plot the bar chart using the function ``bar()``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   183
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   184
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   185
   bar(year,profit)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   186
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   187
Note that the function ``bar()`` needs at least two arguments one the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   188
values in x-coordinate and the other values in y-coordinate which is
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   189
used to determine the height of the bars.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   190
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   191
{{{ switch to the next slide which has the problem statement of
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   192
problem to be tried out }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   193
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   194
Now here is a question for you to try, plot a bar chart which is not
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   195
filled and which is hatched with 45\ :sup:`o` slanting lines as shown
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   196
in the image in the slide. The data for the chart may be obtained from
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   197
the file ``company-a-data.txt``.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   198
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   199
.. **Clue** - *try bar? in your ipython interpreter* 
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   200
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   201
.. bar(year,profit,fill=False,hatch='/')
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   202
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   203
{{{ switch to the slide which says about log-log graph }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   204
471
462f9d3f0418 Language check done of `The other kinds of plots`
bhanu
parents: 369
diff changeset
   205
Now let us move on to the log-log plot. A log-log graph or a log-log plot is
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   206
a two-dimensional graph of numerical data that uses logarithmic scales
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   207
on both the horizontal and vertical axes. Because of the nonlinear
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   208
scaling of the axes, a function of the form y = ax\ :sup:`b` will
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   209
appear as a straight line on a log-log graph
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   210
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   211
{{{ switch to the slide showing the problem statement of fourth
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   212
exercise question }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   213
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   214
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   215
Plot a `log-log` chart of y=5*x\ :sup:`3` for x from 1-20.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   216
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   217
Before we actually plot let us calculate the points needed for
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   218
that. 
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   219
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   220
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   221
    x = linspace(1,20,100)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   222
    y = 5*x**3
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   223
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   224
{{{ switch to next slide, ``loglog()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   225
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   226
Now we can plot the log-log chart using ``loglog()`` function,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   227
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   228
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   229
    loglog(x,y)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   230
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   231
To understand the difference between a normal ``plot`` and a ``log-log
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   232
plot`` let us create another plot using the function ``plot``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   233
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   234
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   235
    figure(2)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   236
    plot(x,y)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   237
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   238
{{{ show both the plots side by side }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   239
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   240
So that was ``log-log() plot``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   241
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   242
{{{ switch to the next slide which says: "How to get help on
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   243
matplotlib online"}}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   244
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   245
Now we will see few more plots and also see how to access help of
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   246
matplotlib over the internet.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   247
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   248
Help about matplotlib can be obtained from
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   249
matplotlib.sourceforge.net/contents.html
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   250
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   251
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   252
More plots can be seen at
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   253
matplotlib.sourceforge.net/users/screenshots.html and also at
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   254
matplotlib.sourceforge.net/gallery.html
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   255
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   256
{{{ switch to summary slide }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   257
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   258
Now we have come to the end of this tutorial. We have covered scatter
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   259
plot, pie chart, bar chart, log-log plot and also saw few other plots
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   260
and covered how to access the matplotlib online help.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   262
{{{ switch to the thank you slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   263
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   264
Thank you!