Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Comparing two datasets in the same plot is a very convenient feature in AIDA. However, those two datasets may not always have the same scale, or even the same units. JAS3 lets you add a secondary Y Axis, which can be scaled independently of the primary one. Just select the Data tab in the Plot Properties dialog. For each data set listed on the left-hand side, you can select which axis to associate it with by selecting either Y0 for the primary Y Axis on the left-hand side of the plot, or Y1 for the secondary Y Axis on the right-hand side of the plot. The properties of each axis, like range and label can be changed in the Y Axis tab.
You can also do it in a program:

Code Block
//////////////////////
import hep.aida.*;
import java.util.Random;

public class SecondAxis {
    public static void main(String[] argv) {
        
        IAnalysisFactory af = IAnalysisFactory.create();
        ITree tree = af.createTreeFactory().create();
        IHistogramFactory hf = af.createHistogramFactory(tree);
        
        IHistogram1D h1 = hf.createHistogram1D("h1",100,-6,4);
        IHistogram1D h2 = hf.createHistogram1D("h2",100,-4,6);
        
        Random r = new Random();
        
        for ( int i = 0; i<1000; i++ ) {
            h1.fill(r.nextGaussian()-1.);
            h2.fill(r.nextGaussian()+1.);
            h2.fill(r.nextGaussian()+1.);
        }
        
        IPlotterFactory plotterFactory = af.createPlotterFactory();
        IPlotter plotter = plotterFactory.create("Styles.java plot");
             
       // Change the default styles for the region to hide 
       // legend and statistics
        IPlotterStyle regionStyle = plotter.region(0).style();
        regionStyle.legendBoxStyle().setVisible(false);
        regionStyle.statisticsBoxStyle().setVisible(false);


        // >>>>> This style overwrites default "Y0" position of y axis
        //
        IPlotterStyle style = plotterFactory.createPlotterStyle();
        style.yAxisStyle().setParameter("yAxis", "Y1");
        //
        // >>>>>

        plotter.region(0).plot(h1);
        plotter.region(0).plot(h2, style);
        
       plotter.show();
    }
}

...