PowerPlotPercolation logo

Scientific fit plot

This is a plot of actual data taken from Phys.Rev. D82:094592, 2010, further code for fits and data can be found on http://www.field-theory.org. Note that the error band has been scaled up to make it more visual.

This page describes the class “FormFactor” in the PowerPlot demo app.

Scientific data 2

This plot combines several different elements: a coordinate axis, a plot of data with uncertainties, a line with the best fit to the data and a region with gray filling representing the uncertainty of the best fit. While the first two elements (the axis and the data) can be generated by a factory method, the other two elements have to be added manually. We also have to take care that the elements are arranged in the correct order since they are drawn in the order they occur in WSChart.

    // Step 1: Basic chart with coordinate system and data points with uncertainties.
    WSChart *formFactorChart = [WSChart linePlotWithFrame:[self.view bounds]
                                                     data:[DemoData formFactorMeasured]
                                                   labelX:NSLocalizedString(@"Virtuality", @"")
                                                   labelY:NSLocalizedString(@"F1 form factor", @"")];
    WSPlotData *dataPlot = (WSPlotData *)[[formFactorChart plotAtIndex:0] view];
    dataPlot.lineStyle = kLineNone;
    dataPlot.propDefault.symbolStyle = kSymbolDiamond;
    dataPlot.propDefault.symbolSize = 10;

The first step is straightforward. The axis and the data plot are generated by a factory method. Then the data plot is configured to display diamond symbols of size 10 and to have no lines connecting the data points.

    // Step 2: The best fit line.
    [formFactorChart generateControllerWithData:[DemoData formFactorFit]
                                      plotClass:[WSPlotData class]
                                          frame:[self.view bounds]];
    WSPlotData *bestFit = (WSPlotData *)[[formFactorChart lastPlot] view];
    bestFit.lineWidth = 2;
    bestFit.lineColor = [UIColor blackColor];
    bestFit.propDefault.symbolStyle = kSymbolNone;

In step two we add the best fit line to the graph, using a black color and a width of 2.

    // Step 3: The uncertainty error band.
    [formFactorChart generateControllerWithData:[[DemoData formFactorFit] contourWithError]
                                      plotClass:[WSPlotRegion class]
                                          frame:[self.view bounds]];
    WSPlotRegion *errorBand = (WSPlotRegion *)[[formFactorChart lastPlot] view];
    errorBand.fillColor = [UIColor grayColor];
    errorBand.lineColor = [UIColor clearColor];

The last element is the region with the uncertainty of the best fit. Note that the DemoData class has both the best fit and the uncertainty at each point. This data is not yet appropriate for a plot with WSPlotRegion, so we use the factory method contourWithError that generates a contour from the linear data and can be used as input for WSPlotRegion.

    // Ensure proper ordering of plots.
    [formFactorChart exchangePlotAtIndex:0 withPlotAtIndex:3];

    // Scale all axis and set the ticks and labels.
    [formFactorChart autoscaleAllAxisX];
    [formFactorChart autoscaleAllAxisY];
    [[formFactorChart firstPlotAxis] autoTicksXD];
    [[formFactorChart firstPlotAxis] setTickLabelsX];
    [[formFactorChart firstPlotAxis] autoTicksYD];
    [[formFactorChart firstPlotAxis] setTickLabelsY];

The final step is to exchange the first plot with the error band plot which makes sure that the error band is at the bottom and does not cover the other objects. The last set of commands scale all axis and generates appropriate ticks and labels.