\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 . 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 tag and 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 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} @X @Y
What is the amplitude of this function?
\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 tag. Gridlines can be set using the and 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 , <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 @X @Y
What is the amplitude of this function? \end{verbatim} \includegraphics{dynamic_plot2}