other_types_of_plots.rst
author Nishanth <nishanth@fossee.in>
Fri, 08 Oct 2010 23:55:07 +0530
changeset 256 a3aa223c1662
parent 160 f394adb5b00e
permissions -rw-r--r--
added script to using_sage_to_teach
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
160
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     1
.. 2.4 LO: other types of plots (3) [anoop] 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     2
.. -----------------------------------------
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     3
.. * scatter 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     4
.. * pie chart 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     5
.. * bar chart 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     6
.. * log 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     7
.. * illustration of other plots, matplotlib help
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     8
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
     9
===================
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    10
Other type of plots
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    11
===================
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    12
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    13
{{{ show the first slide }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    14
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    15
Hello and welcome to the tutorial other type of plots.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    16
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    17
{{{ show the outline slide }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    18
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    19
In this tutorial we will cover scatter plot, pie chart, bar chart and
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    20
log plot. We will also see few other plots and also introduce you to
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    21
the matplotlib help.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    22
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    23
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    24
Let us start with scatter plot. 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    25
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    26
{{{ switch to the next slide }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    27
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    28
In a scatter plot, the data is displayed as a collection of points,
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    29
each having the value of one variable determining the position on the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    30
horizontal axis and the value of the other variable determining the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    31
position on the vertical axis. This kind of plot is also called a
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    32
scatter chart, scatter diagram and scatter graph.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    33
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    34
Before we proceed further get your IPython interpreter running with
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    35
the ``-pylab`` option. Start your IPython interpreter as
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    36
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    37
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    38
    ipython -pylab
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    39
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    40
{{{ open the ipython interpreter in the terminal using the command
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    41
ipython -pylab }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    42
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    43
{{{ switch to the next slide having the problem statement of first
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    44
exercise }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    45
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    46
Now, let us plot a scatter plot showing the percentage profit of company A
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    47
from the year 2000-2010. The data for the same is available in the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    48
file ``company-a-data.txt``. 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    49
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    50
{{{ open the file company-a-data.txt and show the content }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    51
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    52
The data file has two lines with a set of values in each line, the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    53
first line representing years and the second line representing the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    54
profit percentages.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    55
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    56
{{{ close the file and switch to the terminal }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    57
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    58
To product the scatter plot first we need to load the data from the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    59
file using ``loadtxt``. We learned in one of the previous sessions,
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    60
and it can be done as ::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    61
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    62
    year,profit = loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    63
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    64
Now in-order to generate the scatter graph we will use the function 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    65
``scatter()`` 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    66
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    67
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    68
	scatter(year,profit)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    69
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    70
Notice that we passed two arguments to ``scatter()`` function, first
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    71
one the values in x-coordinate, year, and the other the values in
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    72
y-coordinate, the profit percentage.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    73
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    74
{{{ switch to the next slide which has the problem statement of
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    75
problem to be tried out }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    76
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    77
Now here is a question for you to try out, plot the same data with red
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    78
diamonds. 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    79
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    80
**Clue** - *try scatter? in your ipython interpreter* 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    81
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    82
.. scatter(year,profit,color='r',marker='d')
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    83
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    84
Now let us move on to pie chart.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    85
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    86
{{{ switch to the slide which says about pie chart }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    87
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    88
A pie chart or a circle graph is a circular chart divided into
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    89
sectors, illustrating proportion.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    90
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    91
{{{ switch to the slide showing the problem statement of second
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    92
exercise question }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    93
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    94
Plot a pie chart representing the profit percentage of company A, with
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    95
the same data from file ``company-a-data.txt``. So let us reuse the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    96
data we have loaded from the file previously.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    97
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    98
We can plot the pie chart using the function ``pie()``.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
    99
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   100
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   101
   pie(profit,labels=year)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   102
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   103
Notice that we passed two arguments to the function ``pie()``. The
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   104
first one the values and the next one the set of labels to be used in
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   105
the pie chart.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   106
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   107
{{{ switch to the next slide which has the problem statement of
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   108
problem to be tried out }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   109
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   110
Now here is a question for you to try out, plot a pie chart with the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   111
same data with colors for each wedges as white, red, black, magenta,
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   112
yellow, blue, green, cyan, yellow, magenta and blue respectively.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   113
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   114
**Clue** - *try pie? in your ipython interpreter* 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   115
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   116
.. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b'))
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   117
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   118
{{{ switch to the slide which says about bar chart }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   119
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   120
Now let us move on to bar chart. A bar chart or bar graph is a chart
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   121
with rectangular bars with lengths proportional to the values that
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   122
they represent.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   123
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   124
{{{ switch to the slide showing the problem statement of third
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   125
exercise question }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   126
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   127
Plot a bar chart representing the profit percentage of company A, with
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   128
the same data from file ``company-a-data.txt``. 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   129
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   130
So let us reuse the data we have loaded from the file previously.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   131
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   132
We can plot the bar chart using the function ``bar()``.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   133
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   134
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   135
   bar(year,profit)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   136
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   137
Note that the function ``bar()`` needs at least two arguments one the
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   138
values in x-coordinate and the other values in y-coordinate which is
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   139
used to determine the height of the bars.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   140
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   141
{{{ switch to the next slide which has the problem statement of
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   142
problem to be tried out }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   143
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   144
Now here is a question for you to try, plot a bar chart which is not
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   145
filled and which is hatched with 45\ :sup:`o` slanting lines as shown
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   146
in the image in the slide.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   147
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   148
**Clue** - *try bar? in your ipython interpreter* 
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   149
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   150
.. bar(year,profit,fill=False,hatch='/')
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   151
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   152
{{{ switch to the slide which says about bar chart }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   153
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   154
Now let us move on to log-log plot. A log-log graph or log-log plot is
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   155
a two-dimensional graph of numerical data that uses logarithmic scales
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   156
on both the horizontal and vertical axes. Because of the nonlinear
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   157
scaling of the axes, a function of the form y = ax\ :sup:`b` will
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   158
appear as a straight line on a log-log graph
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   159
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   160
{{{ switch to the slide showing the problem statement of fourth
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   161
exercise question }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   162
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   163
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   164
Plot a `log-log` chart of y=5*x\ :sup:`3` for x from 1-20.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   165
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   166
Before we actually plot let us calculate the points needed for
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   167
that. And it could be done as,
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   168
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   169
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   170
    x = linspace(1,20,100)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   171
    y = 5*x**3
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   172
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   173
Now we can plot the log-log chart using ``loglog()`` function,
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   174
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   175
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   176
    loglog(x,y)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   177
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   178
To understand the difference between a normal ``plot`` and a ``log-log
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   179
plot`` let us create another plot using the function ``plot``.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   180
::
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   181
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   182
    figure(2)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   183
    plot(x,y)
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   184
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   185
{{{ show both the plots side by side }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   186
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   187
So that was ``log-log() plot``.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   188
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   189
{{{ switch to the next slide which says: "How to get help on
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   190
matplotlib online"}}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   191
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   192
Now we will see few more plots and also see how to access help of
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   193
matplotlib over the internet.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   194
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   195
Help about matplotlib can be obtained from
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   196
matplotlib.sourceforge.net/contents.html
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   197
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   198
.. #[[Anoop: I am not so sure how to do the rest of it, so I guess we
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   199
   can just browse through the side and tell them few. What is your
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   200
   opinion??]]
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   201
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   202
Now let us see few plots from
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   203
matplotlib.sourceforge.net/users/screenshots.html
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   204
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   205
{{{ browse through the site quickly }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   206
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   207
{{{ switch to recap slide }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   208
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   209
Now we have come to the end of this tutorial. We have covered scatter
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   210
plot, pie chart, bar chart, log-log plot and also saw few other plots
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   211
and covered how to access the matplotlib online help.
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   212
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   213
{{{ switch to the thank you slide }}}
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   214
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   215
Thank you!
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   216
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   217
..  Author: Anoop Jacob Thomas <anoop@fossee.in>
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   218
    Reviewer 1:
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   219
    Reviewer 2:
f394adb5b00e added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff changeset
   220
    External reviewer: