diff --git a/doplot.go b/doplot.go index c674b3065cc1e7c9152251ba1a01e0da5f2dff4f..93bc234cab21e6c17bfff65d34a67342c7982105 100644 --- a/doplot.go +++ b/doplot.go @@ -25,15 +25,12 @@ const ( // plot size.. my arbitrary choice ) // oneplot saves us doing the same point copying, adding three times. -// I also toss out the first two points. They are a bit silly and -// have massive errors. func oneplot(y []float32) (*plot.Plot, error) { p := plot.New() points := make(plotter.XYs, len(y)) for i, piV := range y { points[i] = plotter.XY{X: float64(i + 1), Y: float64(piV)} - } // Toss out the first two y-values... - points[0].Y, points[1].Y = points[2].Y, points[2].Y + } if line, err := plotter.NewScatter(points); err != nil { return nil, err } else { @@ -42,6 +39,22 @@ func oneplot(y []float32) (*plot.Plot, error) { return p, nil } +// fixStdErr takes the standard error slice and replaces all the +// initial zero entries with the first non-zero entry. This is a +// question of aesthetics, not numerics. It looks silly to have an +// error value that starts at zero and then jumps up. +func fixStdErr(stdErr []float32) { + n := 0 + for n = range stdErr { + if stdErr[n] != 0.0 { + break + } + } + for j := 0; j < n; j++ { + stdErr[j] = stdErr[n] + } +} + // doplot copies the data and calls the plotters and writes a jpg // file to plotname. If plotname has not been set, we just return. // It is not an error. @@ -52,15 +65,17 @@ func doplot(pi, stdErr []float32, plotName string) error { const step = "step" var pPi, pStd, pAbs *plot.Plot var err error + if pPi, err = oneplot(pi); err != nil { // pi estimate return err } pPi.Title.Text = "π estimate" pPi.Y.Label.Text = "π" - + fixStdErr(stdErr) if pStd, err = oneplot(stdErr); err != nil { // std error return err } + pStd.Title.Text = "standard error" pStd.Y.Label.Text = "std error"