Example 5: Displaying Marginal Distributions

The IMLPlus program for this example is in the file Example5-DashDotPlot.sx in the directory <IMLStudio>\Programs\Samples\Annotation Examples, where <IMLStudio> is the directory in which you installed IML Studio.

This example defines a module that displays hash marks in the margins of a scatter plot. The hash marks indicate the marginal distribution for each variable.

Because the scatter plot does not display markers when either coordinate is a missing value, the module strips out missing values before plotting the marginal distribution. To eliminate needless overplotting, the module eliminates duplicate values for each variable.

The module gets the margins of the plot and the view range of each axis. That information is used to figure out what values (in data coordinates) correspond to the left and bottom of the frame that surrounds the Plot Area.

All modules that change the graphical state of a plot have the responsibility to save the graphical state before making any changes and to restore the graphical state before exiting. This is done with the DrawPushState and DrawPopState methods. Pushing and popping the graphical state ensures that the program calling the module knows that the state is the same after the module call as it was before the module call.

The module plots the marginal distribution of the X variable by making hash marks that go from the bottom of the plot frame to halfway up the bottom plot margin. The marginal distribution of the Y variable is displayed by using hash marks from the left edge of the plot frame to halfway along the left plot margin.