other-type-of-plots/script.rst
author Puneeth Chaganti <punchagan@gmail.com>
Tue, 26 Oct 2010 14:50:33 +0530
changeset 354 4c09238600e0
parent 319 e8c02b3c51ac
child 369 8988867e0470
permissions -rw-r--r--
Reviewed other types of plots.
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>
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    21
   Internal Reviewer   : 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    22
   External Reviewer   :
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    23
   Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 308
diff changeset
    24
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    25
.. #[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
    26
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
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
    29
===================
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
{{{ 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
    32
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
Hello and welcome to the tutorial 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
    34
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    35
.. #[Puneeth: this sentence doesn't read well]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    36
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
    37
{{{ 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
    38
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    39
.. #[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
    40
.. 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
    41
.. while, etc.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    42
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
    43
In this tutorial we will cover scatter plot, pie chart, bar chart and
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    44
log-log plot. We will also see few other plots and also introduce you to
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
    45
the matplotlib 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
    46
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    47
.. #[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
    48
.. "We" include the viewer or not?]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    49
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
    50
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
    51
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    52
{{{ 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
    53
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    54
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
    55
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
    56
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
    57
position on the vertical axis. This kind of plot is also called a
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
scatter chart, scatter diagram and scatter 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
    59
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    60
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
    61
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    62
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
    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
    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
{{{ 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
    66
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
    67
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
{{{ 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
    69
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
    70
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    71
Now, let us plot a scatter plot showing the percentage profit of
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    72
company A from the year 2000-2010. The data for the same is available
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    73
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
    74
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    75
{{{ 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
    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
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
    78
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
    79
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
    80
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
{{{ 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
    82
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    83
To produce the scatter plot first we 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
    84
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
    85
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
    86
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    87
    year,profit =
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    88
    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
    89
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    90
.. #[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
    91
.. the loadtxt tutorial.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
    92
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    93
{{{ switch to next slide, ``scatter`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    94
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
    95
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
    96
``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
    97
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    98
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    99
	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
   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
   101
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
   102
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
   103
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
   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
{{{ 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
   106
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
   107
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
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
   109
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
   110
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   111
.. **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
   112
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   113
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
   114
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   115
.. 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
   116
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   117
Now let us move on to 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
   118
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   119
.. #[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
   120
.. chart for the same data. continuity, will be good.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   121
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
   122
{{{ 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
   123
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
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
   125
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
   126
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   127
{{{ 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
   128
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
   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
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
   131
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
   132
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
   133
354
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   134
.. #[Puneeth, this part can be move above.]
4c09238600e0 Reviewed other types of plots.
Puneeth Chaganti <punchagan@gmail.com>
parents: 319
diff changeset
   135
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   136
{{{ switch to next slide, ``pie()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   137
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
   138
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
   139
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   140
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   141
   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
   142
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   143
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
   144
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
   145
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
   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
{{{ 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
   148
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
   149
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   150
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
   151
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
   152
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
   153
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   154
.. **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
   155
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   156
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
   157
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
.. 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
   159
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   160
{{{ 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
   161
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   162
Now let us move on to bar chart. A bar chart or bar graph is a 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
   163
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
   164
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
   165
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   166
{{{ 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
   167
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
   168
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
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
   170
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
   171
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   172
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
   173
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   174
{{{ 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
   175
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
   176
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
   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
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
   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
   180
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   181
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
   182
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
   183
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
   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
{{{ 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
   186
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
   187
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
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
   189
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
   190
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
   191
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
   192
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   193
.. **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
   194
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
.. 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
   196
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   197
{{{ 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
   198
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   199
Now let us move on to log-log plot. A log-log graph or log-log plot 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
   200
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
   201
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
   202
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
   203
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
   204
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   205
{{{ 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
   206
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
   207
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
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
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
   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
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
   212
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
   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
    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
   216
    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
   217
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   218
{{{ switch to next slide, ``loglog()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   219
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
   220
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
   221
::
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
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
    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
   224
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   225
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
   226
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
   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
    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
   230
    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
   231
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
{{{ 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
   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
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
   235
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
{{{ 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
   237
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
   238
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
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
   240
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
   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
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
   243
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
   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
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   246
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
   247
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
   248
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
   249
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   250
{{{ 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
   251
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   252
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
   253
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
   254
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
   255
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   256
{{{ 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
   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
Thank you!