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