From 61f9235b650bed31ecbd02af47e3c4ff316cdc59 Mon Sep 17 00:00:00 2001
From: "Andrew E. Torda" <torda@zbh.uni-hamburg.de>
Date: Tue, 1 Mar 2022 16:29:36 +0100
Subject: [PATCH] When adding steps for plotting, we have to add in every point
 twice, so we get a step shape and not interpolation.

---
 mc_work/dorun.go | 10 ++++++----
 ui/output_tab.go |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/mc_work/dorun.go b/mc_work/dorun.go
index b8de2ac..317e7a4 100644
--- a/mc_work/dorun.go
+++ b/mc_work/dorun.go
@@ -186,9 +186,10 @@ func saveStep(cprm *cprm, n int, tmprtr float64, x []float32, fTrial float64) {
 		xprev = cprm.plotXtrj[len(cprm.plotXtrj)-len(x):]
 	}
 	cprm.plotnstp = append(cprm.plotnstp, float64(n), float64(n)) // num steps
-	if cprm.fplotWrt != nil {                         // Function values
-		cprm.plotf = append(cprm.plotf, fprev) // copy the last coordinates
-		cprm.plotf = append(cprm.plotf, fTrial) // and append them
+	if cprm.fplotWrt != nil {                                     // Function values
+		cprm.plotf = append(cprm.plotf, fprev)            // copy the last coordinates
+		cprm.plotf = append(cprm.plotf, fTrial)           // and append them
+		cprm.plotTmprtr = append(cprm.plotTmprtr, tmprtr) // then the new ones
 		cprm.plotTmprtr = append(cprm.plotTmprtr, tmprtr) // then the new ones
 	}
 	if cprm.xplotWrt != nil { // The trajectory
@@ -299,11 +300,12 @@ func DoRun(mcPrm *McPrm) (MCresult, error) {
 	if fTrial != fOld { // last move was not accepted, so we have to add last step
 		saveStep(&cprm, mcPrm.NStep, tmprtr, x, fOld)
 	}
+
 	defer fmt.Println("n accepted:", nAcc, "of", mcPrm.NStep)
 	if bestX != nil {
 		defer fmt.Printf("Best function value: %.2f at %.2v\n", bestfval, bestX)
 	} else {
-		defer fmt.Println ("bestX was never initialised")
+		defer fmt.Println("bestX was never initialised")
 	}
 	if err := plotfWrt(&cprm); err != nil {
 		return broken, err
diff --git a/ui/output_tab.go b/ui/output_tab.go
index fc69ec2..e7e17f4 100644
--- a/ui/output_tab.go
+++ b/ui/output_tab.go
@@ -30,8 +30,8 @@ import (
 func runStatTxt(rslt *mcwork.MCresult) fyne.Widget {
 	t1 := fmt.Sprintf("Num steps %d\nNum accepted %d\nacceptance rate %.1f %%\n",
 		rslt.NStep, rslt.NAcc, (float32(rslt.NAcc)/float32(rslt.NStep))*100.)
-	t2 := fmt.Sprintf ("best function value: %.2f\nat %.1g", rslt.Bestfval, rslt.BestX)
-	r := widget.NewLabel(t1+t2)
+	t2 := fmt.Sprintf("best function value: %.2f\nat %.1g", rslt.Bestfval, rslt.BestX)
+	r := widget.NewLabel(t1 + t2)
 	return r
 }
 
-- 
GitLab