other-type-of-plots/script.rst
author amit
Wed, 13 Oct 2010 17:32:59 +0530
changeset 324 4054b1a6392d
parent 319 e8c02b3c51ac
child 354 4c09238600e0
permissions -rw-r--r--
merging heads
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
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
    25
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
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
    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
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
{{{ 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
    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
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
    33
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
{{{ 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
    35
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    36
In this tutorial we will cover scatter plot, pie chart, bar chart and
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    37
loglog 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
    38
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
    39
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    40
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
    41
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    42
{{{ 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
    43
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    44
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
    45
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
    46
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
    47
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
    48
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
    49
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
Before we proceed further get your IPython interpreter running 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
    51
the ``-pylab`` option. Start your IPython interpreter 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
    52
::
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
    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
    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
{{{ 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
    57
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
    58
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
{{{ 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
    60
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
    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
Now, let us plot a scatter plot showing the percentage profit of company 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
    63
from the year 2000-2010. The data for the same is available in 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
    64
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
    65
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
{{{ 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
    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
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
    69
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
    70
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
    71
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
{{{ 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
    73
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    74
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
    75
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
    76
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
    77
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    78
    year,profit =
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    79
    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
    80
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    81
{{{ switch to next slide, ``scatter`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    82
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
    83
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
    84
``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
    85
::
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
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
	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
    88
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
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
    90
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
    91
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
    92
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    93
{{{ 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
    94
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
    95
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
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
    97
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
    98
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
    99
.. **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
   100
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   101
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
   102
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
.. 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
   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
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
   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
{{{ 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
   108
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
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
   110
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
   111
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
{{{ 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
   113
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
   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
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
   116
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
   117
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
   118
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   119
{{{ switch to next slide, ``pie()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   120
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
   121
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
   122
::
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
   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
   125
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   126
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
   127
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
   128
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
   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
{{{ 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
   131
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
   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
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
   134
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
   135
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
   136
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   137
.. **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
   138
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   139
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
   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(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
   142
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   143
{{{ 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
   144
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
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
   146
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
   147
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
   148
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   149
{{{ 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
   150
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
   151
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
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
   153
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
   154
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
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
   156
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   157
{{{ 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
   158
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
   159
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
   160
::
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
   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
   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
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
   165
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
   166
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
   167
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
{{{ 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
   169
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
   170
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
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
   172
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
   173
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
   174
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
   175
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   176
.. **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
   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
.. 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
   179
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   180
{{{ 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
   181
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
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
   183
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
   184
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
   185
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
   186
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
   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
{{{ 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
   189
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
   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
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
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
   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
Before we actually plot let us calculate the points needed for
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
that. And it could 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
   196
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   197
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
    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
   199
    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
   200
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   201
{{{ switch to next slide, ``loglog()`` function }}}
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   202
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
   203
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
   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
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
    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
   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
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
   209
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
   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
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
    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
   213
    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
   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
{{{ 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
   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
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
   218
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
{{{ 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
   220
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
   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
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
   223
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
   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
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
   226
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
   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
288
a3b98b4c371e added few questions for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   229
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
   230
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
   231
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
   232
308
0a0a91fb3a0d added slides for other-type-of-plots.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 288
diff changeset
   233
{{{ 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
   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
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
   236
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
   237
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
   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
{{{ 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
   240
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
Thank you!