These plots can be added to each other to synthesize more complex plot types.
The WPlot class is plot-centric. Use WPlot to generate Waterloo plots then invoke the plot's createFrame() method to display it.These static methods also provide some convenience parsing, e.g.:
- to allow named web colors to be converted to their Java sRGB equivalents.
- to automatically coerce Groovy data types to the required Java type
A simple way to invoke these methods in the Groovy Console is to call them with the property name/ value pairs supplied as an ArrayList: to do that use square brackets as shown below.
import kcl.waterloo.plot.WPlot p=WPlot.scatter(['XData', 1..10, 'YData', 1..10])Because the input is an ArrayList, the code will pre-process the input arguments - formatting them ready for the Java code. This pre-processing stage understands MATLAB style arguments such as "FaceColor" and "LineStyle" as explained here. However, it is recommended to avoid this in Groovy code and use Waterloo property names instead. In that case we can use a LinkedHasMap as the input instead:
import kcl.waterloo.plot.WPlot p=WPlot.scatter(['XData': 1..10, 'YData': 1..10])Note the only difference here is the use of ":"s instead of ","s in the argument.
The "1..10"s above produce Groovy IntRange variables. The Waterloo Java code does not understand those, but the pre-processing stage will coerce them into arrays of type double, which Java does understand.
This code an instance of the WPlot class. Only two instance methods are of much interest for the moment:
- getPlot - returns a reference to the Waterloo plot instance
- createFrame - displays the plot
p.createFrame();Note that the returned result, f, is a Waterloo GCFrame: a Swing JFrame subclass (shown to the right).
Both the Java plot classes and WPlot implement the createFrame method. It is a convenience mechanism to display simple plots. Alternatively, you can use the Java library to create graph containers and add plots to them. That way you can create grids of plots.