1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package plotter_test
import (
"image/color"
"log"
"math"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
)
// Example_logScale shows how to create a plot with a log-scale on the Y-axis.
func Example_logScale() {
p, err := plot.New()
if err != nil {
log.Fatal(err)
}
p.Title.Text = "My Plot"
p.Y.Scale = plot.LogScale{}
p.Y.Tick.Marker = plot.LogTicks{}
p.X.Label.Text = "x"
p.Y.Label.Text = "f(x)"
f := plotter.NewFunction(math.Exp)
f.XMin = 0.2
f.XMax = 10
f.Color = color.RGBA{R: 255, A: 255}
p.Add(f, plotter.NewGrid())
p.Legend.Add("exp(x)", f)
p.X.Min = f.XMin
p.X.Max = f.XMax
p.Y.Min = math.Exp(f.XMin)
p.Y.Max = math.Exp(f.XMax)
err = p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/logscale.png")
if err != nil {
log.Panic(err)
}
}
|