diff --git a/ackwork/plot.go b/ackwork/plot.go index 6a1c9f08a17f3402e23b214181e264f1f6594e77..3d820b50361f29fc78009c5e65a78de5026343ff 100644 --- a/ackwork/plot.go +++ b/ackwork/plot.go @@ -24,7 +24,7 @@ import ( // maketicks gives reasonable default tick locations func maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { - xmin, delta, prcsn := axisDscrpt.Xmin, axisDscrpt.Delta, axisDscrpt.Prcsn + xmin, xmax, delta, prcsn := axisDscrpt.Xmin, axisDscrpt.Xmax, axisDscrpt.Delta, axisDscrpt.Prcsn rnge := axisDscrpt.Xmax - axisDscrpt.Xmin ntick := int(math.Round((rnge / delta) + 1)) t := make([]chart.Tick, ntick) @@ -34,6 +34,25 @@ func maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { t[i].Value = t[i-1].Value + delta t[i].Label = fmt.Sprintf("%.*f", prcsn, t[i].Value) } + lastTickVal := t[ntick-1] + if lastTickVal.Value > xmax { + t = t[:ntick-1] + } + return t +} +// maketicks this version works, but usually leaves you wanting one tick more. +func alt_maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { + xmin, xmax, delta, prcsn := axisDscrpt.Xmin, axisDscrpt.Xmax, axisDscrpt.Delta, axisDscrpt.Prcsn + var t []chart.Tick + const fstr = "%.*f" + xv, xl := xmin, fmt.Sprintf(fstr, prcsn, xmin) + if xmin > 3.56 && xmin < 3.58 { + fmt.Println (axisDscrpt) + } + for ; xv <= xmax; xv, xl = xv+delta, fmt.Sprintf("%.*f", prcsn, xv) { + t = append(t, chart.Tick {xv, xl}) + } + return t } @@ -86,10 +105,14 @@ func plotfWrt(cprm *cprm, fname string) error { NameStyle: chart.Style{TextRotationDegrees: 360}, Range: &range2{}, } + } else { // If you do not put something here, go-chart seems + tmprtrAxis = chart.YAxis{} // to mess up the scaling on the + tmprtrAxis.Style = chart.Hidden() // other axis } graph := chart.Chart{ Width: 800, + Title: "cost function", Series: []chart.Series{ chart.ContinuousSeries{ // The function values Name: "cost",