Skip to content
Snippets Groups Projects
Commit 9389829d authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Fixed a tick mark very rarely falling out of the axes.

parent 470e32ce
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
// maketicks gives reasonable default tick locations // maketicks gives reasonable default tick locations
func maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { 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 rnge := axisDscrpt.Xmax - axisDscrpt.Xmin
ntick := int(math.Round((rnge / delta) + 1)) ntick := int(math.Round((rnge / delta) + 1))
t := make([]chart.Tick, ntick) t := make([]chart.Tick, ntick)
...@@ -34,6 +34,25 @@ func maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { ...@@ -34,6 +34,25 @@ func maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick {
t[i].Value = t[i-1].Value + delta t[i].Value = t[i-1].Value + delta
t[i].Label = fmt.Sprintf("%.*f", prcsn, t[i].Value) 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 return t
} }
...@@ -86,10 +105,14 @@ func plotfWrt(cprm *cprm, fname string) error { ...@@ -86,10 +105,14 @@ func plotfWrt(cprm *cprm, fname string) error {
NameStyle: chart.Style{TextRotationDegrees: 360}, NameStyle: chart.Style{TextRotationDegrees: 360},
Range: &range2{}, 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{ graph := chart.Chart{
Width: 800, Width: 800,
Title: "cost function",
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ // The function values chart.ContinuousSeries{ // The function values
Name: "cost", Name: "cost",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment