func main() { // Get some random data. n, m := 5, 10 pts := make([]plotter.XYer, n) for i := range pts { xys := make(plotter.XYs, m) pts[i] = xys center := float64(i) for j := range xys { xys[j].X = center + (rand.Float64() - 0.5) xys[j].Y = center + (rand.Float64() - 0.5) } } plt, err := plot.New() if err != nil { panic(err) } mean95 := plotutil.NewErrorPoints(plotutil.MeanAndConf95, pts...) medMinMax := plotutil.NewErrorPoints(plotutil.MedianAndMinMax, pts...) plotutil.AddLinePoints(plt, "mean and 95% confidence", mean95, "median and minimum and maximum", medMinMax) plotutil.AddErrorBars(plt, mean95, medMinMax) plotutil.AddScatters(plt, pts[0], pts[1], pts[2], pts[3], pts[4]) plt.Save(4, 4, "errpoints.png") }
func PlotXvsYGroupedByXs(title, directory string, groupeddss map[string][]*rdb.Dataset, yValuesKey, yValuesLabel, xValuesLabel string) { var plottingPointArgs []interface{} var plottingErrorArgs []interface{} names := map[string]bool{} xKeys := []float64{} for xKey, dssGroup := range groupeddss { xKeys = append(xKeys, datautils.ParseFloatOrFail(xKey)) for _, d := range dssGroup { names[d.GetName()] = true } } sort.Float64s(xKeys) xKeyStrings := []string{} for _, floatVal := range xKeys { xKeyStrings = append(xKeyStrings, strconv.FormatFloat(floatVal, 'f', 1, 64)) } for name, _ := range names { datasetPointsAcrossGroups := []plotter.XYer{} for _, groupKey := range xKeyStrings { dssGroup := groupeddss[groupKey] var ds *rdb.Dataset for _, d := range dssGroup { if d.GetName() == name { ds = d break } } if ds == nil { str := fmt.Sprintf("Couldn't find ds (%s) in dss group (%s)", name, groupKey) panic(str) } values := ds.GetDatasetFloatValues(yValuesKey) if len(values) == 0 { continue } xys := make(plotter.XYs, len(values)) datasetPointsAcrossGroups = append(datasetPointsAcrossGroups, xys) for i, val := range values { xys[i].X = datautils.ParseFloatOrFail(groupKey) xys[i].Y = val } } mean95, err := plotutil.NewErrorPoints(plotutil.MeanAndConf95, datasetPointsAcrossGroups...) if err != nil { fmt.Println(mean95) panic(err) } plottingPointArgs = append(plottingPointArgs, name, mean95) plottingErrorArgs = append(plottingErrorArgs, mean95) } p, err := plot.New() if err != nil { panic(err) } p.Title.Text = title p.X.Label.Text = xValuesLabel p.Y.Label.Text = yValuesLabel plotutil.AddLinePoints(p, plottingPointArgs...) plotutil.AddErrorBars(p, plottingErrorArgs...) savePlot(title, directory, p) }