String plotTitle = "Scatter plot";
String userTitle = getOption(optionalArgs, "-title");
plotTitle = (userTitle != null) ? userTitle : plotTitle;
Plot2D offScreenPlot = new Plot2D();
offScreenPlot.setSize(width, height);
// master plot
PlotData2D master = new PlotData2D(series.get(0));
master.setPlotName(plotTitle);
master.m_displayAllPoints = true;
offScreenPlot.setMasterPlot(master);
Instances masterInstances = series.get(0);
int xAx = getIndexOfAttribute(masterInstances, xAxis);
int yAx = getIndexOfAttribute(masterInstances, yAxis);
if (xAx < 0) {
xAx = 0;
}
if (yAx < 0) {
yAx = 0;
}
// plotting axes and color
offScreenPlot.setXindex(xAx);
offScreenPlot.setYindex(yAx);
offScreenPlot.setCindex(masterInstances.numAttributes() - 1);
String colorAtt = getOption(optionalArgs, "-color");
int tempC = getIndexOfAttribute(masterInstances, colorAtt);
if (tempC >= 0) {
offScreenPlot.setCindex(tempC);
}
String hasErrors = getOption(optionalArgs, "-hasErrors");
// master plot is the error cases
if (hasErrors != null) {
int[] plotShapes = new int[masterInstances.numInstances()];
for (int i = 0; i < plotShapes.length; i++) {
plotShapes[i] = Plot2D.ERROR_SHAPE;
}
master.setShapeType(plotShapes);
}
// look for an additional attribute that stores the
// shape sizes
String shapeSize = getOption(optionalArgs, "-shapeSize");
if (shapeSize != null && shapeSize.length() > 0) {
int shapeSizeI = getIndexOfAttribute(masterInstances, shapeSize);
if (shapeSizeI >= 0) {
int[] plotSizes = new int[masterInstances.numInstances()];
for (int i = 0; i < masterInstances.numInstances(); i++) {
plotSizes[i] = (int)masterInstances.instance(i).value(shapeSizeI);
}
master.setShapeSize(plotSizes);
}
}
// additional plots
if (series.size() > 1) {
for (Instances plotI : series) {
PlotData2D plotD = new PlotData2D(plotI);
plotD.m_displayAllPoints = true;
offScreenPlot.addPlot(plotD);
if (shapeSize != null && shapeSize.length() > 0) {
int shapeSizeI = getIndexOfAttribute(plotI, shapeSize);
if (shapeSizeI >= 0) {
int[] plotSizes = new int[plotI.numInstances()];
for (int i = 0; i < plotI.numInstances(); i++) {
plotSizes[i] = (int)plotI.instance(i).value(shapeSizeI);
}
plotD.setShapeSize(plotSizes);
}
}
// all other plots will have x shape if master plot are errors
if (hasErrors != null) {
int[] plotShapes = new int[plotI.numInstances()];
for (int i = 0; i < plotShapes.length; i++) {
plotShapes[i] = Plot2D.X_SHAPE;
}
plotD.setShapeType(plotShapes);
}
}
}
// render
java.awt.Graphics g = osi.getGraphics();
offScreenPlot.paintComponent(g);
return osi;
}