JavaPlot - How to plot more data sets to same graphic?

619 views Asked by At

I want to compare time series data in just one graphic. I added several data sets to same plot and plot it - just one data set is shown. Documentation missing, existing questions useless..

Question: Why is just one data set represented? And also, why is its' title not used to create a legend?

My code (sniped):

//first, create terminal to write png files (not shown)
..

//create the three data sets (just shown for first data set here)
double[][] original = combinedSequence.getOriginalValues();
AbstractPlot originalPlot = new DataSetPlot(original);
originalPlot.setTitle("'original'");
..

//add the three data set plots
p.addPlot(originalPlot);
p.addPlot(offsetPlot);
p.addPlot(functionPlot);

//plot graph
p.newGraph();
p.plot();
1

There are 1 answers

0
Panayotis On

Two things:

  1. newGraph() should be set before any subplot
  2. titles should not have '

So, a correct version of your code will be:

    double[][] original1 = {{2,3},{4,5},{6,7}};
    double[][] original2 = {{8,9},{12,13},{14,15}};
    AbstractPlot originalPlot = new DataSetPlot(original1);
    originalPlot.setTitle("original1");
    AbstractPlot originalPlot2 = new DataSetPlot(original2);
    originalPlot2.setTitle("original2");

    JavaPlot p = new JavaPlot();

    p.addPlot(originalPlot);
    p.newGraph();
    p.addPlot(originalPlot2);

    p.plot();