File:  [LON-CAPA] / loncom / html / adm / help / tex / Authoring_Dynamic_Plot.tex
Revision 1.2: download - view: text, annotated - select for diffs
Tue Sep 14 22:04:42 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_99_1, version_1_2_99_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
- fixing borken TeX

\label{Authoring_Dynamic_Plot}
Dynamically generated plots are used to produce graphs which will be
different for each student who views them. The plots are produced by
calling 'gnuplot', and in fact the xml tag for the plots is <gnuplot>.

Dynamically generated plots should be used in conjunction with a perl
script block which generates the data to be plotted. If you are using
static data a dynamically generated plot is not appropriate because of
the overhead associated with generating the plot. In that case, use a
picture (see \ref{Authoring_Adding_Pictures}).

There are a great deal of parameters that can be set for a plot. These
parameters are accessed by including various sub-tags. By default only
the <gnuplot > tag and <curve > tag are present in a plot. The
sub-tags allow you to define the axes of the plot, the presence of a
key, the placement of gridlines, and the title and legends on the
plot. The example given below shows the use of the <axis > sub-tag to
set the domain and range shown in the graph. 

Below is an example which produces a simple plot. To use it, create a
new problem and \textbf{Edit XML}. Remove all of the text and replace 
it with the text below: 

\begin{verbatim}

 <problem >
 <script type="loncapa/perl" >
 $amplitude = &random(3,5,1);
 for ($x=-6.0; $x<=6.0; $x+=0.05) {
     push @X,$x;
     push @Y, $amplitude * sin($x);
 }
 </script >
 <gnuplot font="medium" width="400" grid="on" 
      height="300" border="on" fgcolor="x000000" 
      alttag="dynamically generated plot" align="center"  
      bgcolor="xffffff" transparent="off" >
     <axis ymin="-6.0" ymax="6.0" xmin="-5.0" 
           xmax="5.0" color="x000000" /> 
     <curve 
          linestyle="lines"
          pointtype="1"
          pointsize="1"
          name=""
          color="x000000" >
         <data >@X</data >
         <data >@Y</data >
     </curve >
 </gnuplot >
 <startouttext /><br />
 What is the amplitude of this function?
 <endouttext />
 <numericalresponse answer="$amplitude" >
 <responseparam type="tolerance" default="5%" name="tol" 
      description="Numerical Tolerance" />
 <responseparam name="sig" type="int_range,0-16" default="0,15"  
      description="Significant Figures" />
 </numericalresponse >
 </problem >

\end{verbatim}

Below is a screenshot (in construction space) of the resulting plot.

\includegraphics{dynamic_plot}

It's likely that the above plot doesn't quite look right. It would be
nice to have the gridlines drawn every 1 unit instead of every 2
units. A title, and labels on the axes, would be a nice
addition. Although it's overkill for this example, we can also add a
key for the plot. We can accomplish these changes by inserting
sub-tags into the <gnuplot > tag. 

Gridlines can be set using the <xtics > and <ytics > tags. The names
of these tags correspond to the names of the commands used in
gnuplot. We specify the beginning, end, and increment of the tick
marks. Gnuplot only puts gridlines on the tick marks. 

Inserting the <title >, <xlabel >, and <ylabel > commands allows us to
set the title and axes labels as one would expect. Inserting a <key >
tag, but not changing any of the information in it, signals gnuplot to
place a key in the graph. If we decide we don't want the key, deleting
the <key > tag will remove it from the graph. 

These changes in the xml are shown below and a screenshot of the new
plot is provided as well. 

\begin{verbatim}

 <problem >
 <script type="loncapa/perl" >
 $amplitude = &random(3,5,1);
 for ($x=-6.0; $x<=6.0; $x+=0.05) {
     push @X,$x;
     push @Y, $amplitude * sin($x);
 }
 </script >
 <gnuplot font="medium" width="400" grid="on" height="300" 
       border="on" fgcolor="x000000" 
       alttag="dynamically generated plot" 
       align="center" bgcolor="xffffff" transparent="off" >
     <key title="" pos="top right" box="off" />
     <ylabel >Y</ylabel >
     <xlabel >X</xlabel >
     <title >A sample plot</title >
     <xtics end="5.0" location="border" start="-5.0" 
            increment="1.0" mirror="on" />
     <ytics end="6.0" location="border" start="-6.0" 
            increment="1.0" mirror="on" />
     <axis ymin="-6.0" ymax="6.0" xmin="-5.0" 
            xmax="5.0" color="x000000" /> 
     <curve linestyle="lines" pointtype="1" pointsize="1" name="f(x)"   
         color="x000000">
         <data >@X</data >
         <data >@Y</data >
     </curve >
 </gnuplot >
 <startouttext />
 <br />
 What is the amplitude of this function?
 <endouttext />
 <numericalresponse answer="$amplitude" >
 <responseparam type="tolerance" default="5%" name="tol" 
      description="Numerical Tolerance" />
 <responseparam name="sig" type="int_range,0-16" default="0,15"  
      description="Significant Figures" />
 </numericalresponse > 
 </problem >

\end{verbatim}

\includegraphics{dynamic_plot2}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>