other-type-of-plots/script.rst
changeset 521 88a01948450d
parent 472 fcdec2d28c9a
equal deleted inserted replaced
520:8249ae9d570a 521:88a01948450d
    18 
    18 
    19      
    19      
    20 .. Author              : Anoop Jacob Thomas <anoop@fossee.in>
    20 .. Author              : Anoop Jacob Thomas <anoop@fossee.in>
    21    Internal Reviewer   : Puneeth
    21    Internal Reviewer   : Puneeth
    22    External Reviewer   :
    22    External Reviewer   :
    23    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    23    Language Reviewer   : Bhanukiran
       
    24    Checklist OK?       : <10-11-2010, Anand, OK> [2010-10-05]
    24 
    25 
    25 .. #[Puneeth: Quickref missing]
    26 .. #[Puneeth: Quickref missing]
    26 
    27 
    27 ===================
    28 ===================
    28 Other type of plots
    29 Other type of plots
    29 ===================
    30 ===================
    30 
    31 
    31 {{{ show the first slide }}}
    32 {{{ show the first slide }}}
    32 
    33 
    33 Hello and welcome to the tutorial other type of plots.
    34 Hello and welcome to the tutorial ``The other kinds of plots``.
    34 
    35 
    35 .. #[Puneeth: this sentence doesn't read well]
    36 .. #[Puneeth: this sentence doesn't read well]
    36 
    37 
    37 {{{ show the outline slide }}}
    38 {{{ show the outline slide }}}
    38 
    39 
    39 .. #[Puneeth: motivate looking at other plots. Why are we looking at
    40 .. #[Puneeth: motivate looking at other plots. Why are we looking at
    40 .. them? Tell that we have only looked at one type of plot all the
    41 .. them? Tell that we have only looked at one type of plot all the
    41 .. while, etc.]
    42 .. while, etc.]
    42 
    43 
    43 Till now we have seen only one type of plot, and in this tutorial us
    44 Till now we have seen only one kind of plotting, and in this tutorial we
    44 see more type of plots like scatter plot, pie chart, bar chart and
    45 are going to see more kinds of plots such as the scatter plot, the pie chart, the bar chart and
    45 log-log plot. We will see few other more plots and also see an
    46 the log-log plot. This tutorial covers the making of other kinds of
    46 introduction to matplotlib help.
    47 plots and also gives an introduction to matplotlib help.
    47 
    48 
    48 .. #[Puneeth: cover, see and introduce you. be consistent. does, the
    49 .. #[Puneeth: cover, see and introduce you. be consistent. does, the
    49 .. "We" include the viewer or not?]
    50 .. "We" include the viewer or not?]
    50 
    51 
    51 Let us start with scatter plot. 
    52 Let us start with scatter plot. 
    54 
    55 
    55 In a scatter plot, the data is displayed as a collection of points,
    56 In a scatter plot, the data is displayed as a collection of points,
    56 each having the value of one variable determining the position on the
    57 each having the value of one variable determining the position on the
    57 horizontal axis and the value of the other variable determining the
    58 horizontal axis and the value of the other variable determining the
    58 position on the vertical axis. This kind of plot is also called a
    59 position on the vertical axis. This kind of plot is also called a
    59 scatter chart, scatter diagram and scatter graph.
    60 scatter chart, a scatter diagram or a scatter graph.
    60 
    61 
    61 Before we proceed further, start your IPython interpreter
    62 Before we proceed further, start your IPython interpreter
    62 ::
    63 ::
    63 
    64 
    64     ipython -pylab
    65     ipython -pylab
    68 
    69 
    69 {{{ switch to the next slide having the problem statement of first
    70 {{{ switch to the next slide having the problem statement of first
    70 exercise }}}
    71 exercise }}}
    71 
    72 
    72 Now, let us plot a scatter plot showing the percentage profit of
    73 Now, let us plot a scatter plot showing the percentage profit of
    73 company A from the year 2000-2010. The data for the same is available
    74 a company A from the year 2000-2010. The data for the same is available
    74 in the file ``company-a-data.txt``.
    75 in the file ``company-a-data.txt``.
    75 
    76 
    76 {{{ open the file company-a-data.txt and show the content }}}
    77 {{{ open the file company-a-data.txt and show the content }}}
    77 
    78 
    78 The data file has two lines with a set of values in each line, the
    79 The data file has two lines with a set of values in each line, the
    79 first line representing years and the second line representing the
    80 first line representing years and the second line representing the
    80 profit percentages.
    81 profit percentages.
    81 
    82 
    82 {{{ close the file and switch to the terminal }}}
    83 {{{ close the file and switch to the terminal }}}
    83 
    84 
    84 To produce the scatter plot first we need to load the data from the
    85 To produce the scatter plot, we first need to load the data from the
    85 file using ``loadtxt``. We learned it in one of the previous sessions,
    86 file using ``loadtxt``. We learned it in one of the previous sessions,
    86 and it can be done as ::
    87 and it can be done as ::
    87 
    88 
    88     year,profit =
    89     year,profit =
    89     loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
    90     loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
   117 
   118 
   118 Pause here and solve the question before moving on.
   119 Pause here and solve the question before moving on.
   119 
   120 
   120 .. scatter(year,profit,color='r',marker='d')
   121 .. scatter(year,profit,color='r',marker='d')
   121 
   122 
   122 Now let us see another plot, pie chart and try to plot the same data
   123 Now let us see another kind of plot, the pie chart, for the same data.
   123 as a pie chart.
       
   124 
   124 
   125 .. #[Puneeth: instead of just saying that, say that let's plot a pie
   125 .. #[Puneeth: instead of just saying that, say that let's plot a pie
   126 .. chart for the same data. continuity, will be good.]
   126 .. chart for the same data. continuity, will be good.]
   127 
   127 
   128 {{{ switch to the slide which says about pie chart }}}
   128 {{{ switch to the slide which says about pie chart }}}
   163 
   163 
   164 .. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b'))
   164 .. pie(t,labels=s,colors=('w','r','k','m','y','b','g','c','y','m','b'))
   165 
   165 
   166 {{{ switch to the slide which says about bar chart }}}
   166 {{{ switch to the slide which says about bar chart }}}
   167 
   167 
   168 Now let us move on to bar chart. A bar chart or bar graph is a chart
   168 Now let us move on to the bar charts. A bar chart or bar graph is a chart
   169 with rectangular bars with lengths proportional to the values that
   169 with rectangular bars with lengths proportional to the values that
   170 they represent.
   170 they represent.
   171 
   171 
   172 {{{ switch to the slide showing the problem statement of fifth
   172 {{{ switch to the slide showing the problem statement of fifth
   173 exercise question }}}
   173 exercise question }}}
   200 
   200 
   201 .. bar(year,profit,fill=False,hatch='/')
   201 .. bar(year,profit,fill=False,hatch='/')
   202 
   202 
   203 {{{ switch to the slide which says about log-log graph }}}
   203 {{{ switch to the slide which says about log-log graph }}}
   204 
   204 
   205 Now let us move on to log-log plot. A log-log graph or log-log plot is
   205 Now let us move on to the log-log plot. A log-log graph or a log-log plot is
   206 a two-dimensional graph of numerical data that uses logarithmic scales
   206 a two-dimensional graph of numerical data that uses logarithmic scales
   207 on both the horizontal and vertical axes. Because of the nonlinear
   207 on both the horizontal and vertical axes. Because of the nonlinear
   208 scaling of the axes, a function of the form y = ax\ :sup:`b` will
   208 scaling of the axes, a function of the form y = ax\ :sup:`b` will
   209 appear as a straight line on a log-log graph
   209 appear as a straight line on a log-log graph
   210 
   210