Annotation of loncom/html/adm/help/tex/Authoring_Dynamic_Plot.tex, revision 1.2

1.1       bowersj2    1: \label{Authoring_Dynamic_Plot}
                      2: Dynamically generated plots are used to produce graphs which will be
                      3: different for each student who views them. The plots are produced by
                      4: calling 'gnuplot', and in fact the xml tag for the plots is <gnuplot>.
                      5: 
                      6: Dynamically generated plots should be used in conjunction with a perl
                      7: script block which generates the data to be plotted. If you are using
                      8: static data a dynamically generated plot is not appropriate because of
                      9: the overhead associated with generating the plot. In that case, use a
                     10: picture (see \ref{Authoring_Adding_Pictures}).
                     11: 
                     12: There are a great deal of parameters that can be set for a plot. These
                     13: parameters are accessed by including various sub-tags. By default only
                     14: the <gnuplot > tag and <curve > tag are present in a plot. The
                     15: sub-tags allow you to define the axes of the plot, the presence of a
                     16: key, the placement of gridlines, and the title and legends on the
                     17: plot. The example given below shows the use of the <axis > sub-tag to
                     18: set the domain and range shown in the graph. 
                     19: 
                     20: Below is an example which produces a simple plot. To use it, create a
                     21: new problem and \textbf{Edit XML}. Remove all of the text and replace 
                     22: it with the text below: 
                     23: 
                     24: \begin{verbatim}
                     25: 
                     26:  <problem >
                     27:  <script type="loncapa/perl" >
                     28:  $amplitude = &random(3,5,1);
                     29:  for ($x=-6.0; $x<=6.0; $x+=0.05) {
                     30:      push @X,$x;
                     31:      push @Y, $amplitude * sin($x);
                     32:  }
                     33:  </script >
                     34:  <gnuplot font="medium" width="400" grid="on" 
                     35:       height="300" border="on" fgcolor="x000000" 
                     36:       alttag="dynamically generated plot" align="center"  
                     37:       bgcolor="xffffff" transparent="off" >
                     38:      <axis ymin="-6.0" ymax="6.0" xmin="-5.0" 
                     39:            xmax="5.0" color="x000000" /> 
                     40:      <curve 
                     41:           linestyle="lines"
                     42:           pointtype="1"
                     43:           pointsize="1"
                     44:           name=""
                     45:           color="x000000" >
                     46:          <data >@X</data >
                     47:          <data >@Y</data >
                     48:      </curve >
                     49:  </gnuplot >
                     50:  <startouttext /><br />
                     51:  What is the amplitude of this function?
                     52:  <endouttext />
                     53:  <numericalresponse answer="$amplitude" >
                     54:  <responseparam type="tolerance" default="5%" name="tol" 
                     55:       description="Numerical Tolerance" />
                     56:  <responseparam name="sig" type="int_range,0-16" default="0,15"  
                     57:       description="Significant Figures" />
                     58:  </numericalresponse >
                     59:  </problem >
                     60: 
                     61: \end{verbatim}
                     62: 
                     63: Below is a screenshot (in construction space) of the resulting plot.
                     64: 
1.2     ! albertel   65: \includegraphics{dynamic_plot}
1.1       bowersj2   66: 
                     67: It's likely that the above plot doesn't quite look right. It would be
                     68: nice to have the gridlines drawn every 1 unit instead of every 2
                     69: units. A title, and labels on the axes, would be a nice
                     70: addition. Although it's overkill for this example, we can also add a
                     71: key for the plot. We can accomplish these changes by inserting
                     72: sub-tags into the <gnuplot > tag. 
                     73: 
                     74: Gridlines can be set using the <xtics > and <ytics > tags. The names
                     75: of these tags correspond to the names of the commands used in
                     76: gnuplot. We specify the beginning, end, and increment of the tick
                     77: marks. Gnuplot only puts gridlines on the tick marks. 
                     78: 
                     79: Inserting the <title >, <xlabel >, and <ylabel > commands allows us to
                     80: set the title and axes labels as one would expect. Inserting a <key >
                     81: tag, but not changing any of the information in it, signals gnuplot to
                     82: place a key in the graph. If we decide we don't want the key, deleting
                     83: the <key > tag will remove it from the graph. 
                     84: 
                     85: These changes in the xml are shown below and a screenshot of the new
                     86: plot is provided as well. 
                     87: 
                     88: \begin{verbatim}
                     89: 
                     90:  <problem >
                     91:  <script type="loncapa/perl" >
                     92:  $amplitude = &random(3,5,1);
                     93:  for ($x=-6.0; $x<=6.0; $x+=0.05) {
                     94:      push @X,$x;
                     95:      push @Y, $amplitude * sin($x);
                     96:  }
                     97:  </script >
                     98:  <gnuplot font="medium" width="400" grid="on" height="300" 
                     99:        border="on" fgcolor="x000000" 
                    100:        alttag="dynamically generated plot" 
                    101:        align="center" bgcolor="xffffff" transparent="off" >
                    102:      <key title="" pos="top right" box="off" />
                    103:      <ylabel >Y</ylabel >
                    104:      <xlabel >X</xlabel >
                    105:      <title >A sample plot</title >
                    106:      <xtics end="5.0" location="border" start="-5.0" 
                    107:             increment="1.0" mirror="on" />
                    108:      <ytics end="6.0" location="border" start="-6.0" 
                    109:             increment="1.0" mirror="on" />
                    110:      <axis ymin="-6.0" ymax="6.0" xmin="-5.0" 
                    111:             xmax="5.0" color="x000000" /> 
                    112:      <curve linestyle="lines" pointtype="1" pointsize="1" name="f(x)"   
                    113:          color="x000000">
                    114:          <data >@X</data >
                    115:          <data >@Y</data >
                    116:      </curve >
                    117:  </gnuplot >
                    118:  <startouttext />
                    119:  <br />
                    120:  What is the amplitude of this function?
                    121:  <endouttext />
                    122:  <numericalresponse answer="$amplitude" >
                    123:  <responseparam type="tolerance" default="5%" name="tol" 
                    124:       description="Numerical Tolerance" />
                    125:  <responseparam name="sig" type="int_range,0-16" default="0,15"  
                    126:       description="Significant Figures" />
                    127:  </numericalresponse > 
                    128:  </problem >
                    129: 
                    130: \end{verbatim}
                    131: 
                    132: \includegraphics{dynamic_plot2}

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