Plotting

We have already seen simple use of plots the AIDA IPlotter interface. By default the plotter contains a single plotting region that covers the entire page, however any number of regions can be defined by the user. These regions may either consist of a regular grid created using the IPlotter.createRegions() method, or an arbitrary arrangement of regions created using the IPlotter.createRegion() method. At any time there is one currentRegion, which is the region that will be used when a new item is plotted. The Plotter allows histograms, clouds, and functions to be plotted. If more than one item is added to the same region the items will be overlaid on the same plot.

The following example shows how to use these methods:

import hep.aida.*;
import java.util.Random;

public class PlotExample
{
   public static void main(String[] argv)
   {
      IAnalysisFactory af = IAnalysisFactory.create();
      IHistogramFactory hf = af.createHistogramFactory(af.createTreeFactory().create());
      
      IHistogram2D h2d = hf.createHistogram2D("test 2d",50,-30,30,50,-3,3);
      
      Random r = new Random();
      for (int i=0; i<10000; i++) 
      {
         h2d.fill(10*r.nextGaussian(),r.nextGaussian());
      }
      
      IPlotter plotter = af.createPlotterFactory().create("Plot");
      plotter.destroyRegions();
      plotter.createRegion(0,0,.66,1).plot(h2d);
      plotter.createRegion(.66,0,.33,.5).plot(hf.projectionX("X Projection",h2d));
      plotter.createRegion(.66,.5,.33,.5).plot(hf.projectionY("Y Projection",h2d));
      plotter.show();
   }
}

Using Styles

In the example below we show how to set the plotter styles using the IPlotterStyle interface. The default styles are first changed for a given region and then overwritten for an individual plot.

import hep.aida.*;
import java.util.Random;

public class PlotWithStyles {

    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,-5,5);
        IHistogram1D h2 = hf.createHistogram1D("h2",100,-5,5);
        
        Random r = new Random();
        
        for ( int i = 0; i<10000; i++ ) {
            h1.fill(r.nextGaussian());
            h2.fill(r.nextGaussian());
        }
        
        IPlotterFactory plotterFactory = af.createPlotterFactory();
        IPlotter plotter = plotterFactory.create("Plotting with Styles");
        
        //This are the default styles for the region
        IPlotterStyle regionStyle = plotter.region(0).style();
        regionStyle.dataStyle().lineStyle().setParameter("color","black");
        regionStyle.xAxisStyle().setLabel("E/m");
        regionStyle.yAxisStyle().setLabel("# Evt");
        
        regionStyle.titleStyle().textStyle().setFontSize(30);
        regionStyle.titleStyle().textStyle().setColor("orange");
        
        regionStyle.xAxisStyle().labelStyle().setFontSize(24);
        regionStyle.xAxisStyle().labelStyle().setItalic(true);
        regionStyle.xAxisStyle().labelStyle().setColor("black");
        regionStyle.xAxisStyle().tickLabelStyle().setFontSize(14);
        regionStyle.xAxisStyle().tickLabelStyle().setBold(true);
        regionStyle.xAxisStyle().tickLabelStyle().setColor("blue");
        
        regionStyle.yAxisStyle().labelStyle().setFontSize(24);
        regionStyle.yAxisStyle().labelStyle().setItalic(true);
        regionStyle.yAxisStyle().labelStyle().setColor("brown");
        regionStyle.yAxisStyle().tickLabelStyle().setFontSize(14);
        regionStyle.yAxisStyle().tickLabelStyle().setBold(true);
        regionStyle.yAxisStyle().tickLabelStyle().setColor("green");
        
        //This styles overwrite some of the region styles
        IPlotterStyle style = plotterFactory.createPlotterStyle();
        style.dataStyle().markerStyle().setParameter("size","12");
        style.dataStyle().markerStyle().setParameter("shape","3");
        style.dataStyle().markerStyle().setParameter("color","blue");
        
        plotter.region(0).plot(h1);
        plotter.region(0).plot(h2,style);
        
        plotter.show();
    }
}

Table of Contents -- Next Section


$Id: plotting.jsp,v 1.1 2006/03/09 18:22:10 turri Exp $