...
1
2
3
4
5 package plotter_test
6
7 import (
8 "image/color"
9 "log"
10 "math"
11
12 "gonum.org/v1/plot"
13 "gonum.org/v1/plot/plotter"
14 "gonum.org/v1/plot/vg"
15 )
16
17 func Example_invertedScale() {
18
19
20
21 p := plot.New()
22 p.Title.Text = "Example of inverted axes"
23 p.Y.Scale = plot.InvertedScale{Normalizer: plot.LogScale{}}
24 p.X.Scale = plot.InvertedScale{Normalizer: plot.LinearScale{}}
25 p.Y.Tick.Marker = plot.LogTicks{Prec: -1}
26 p.X.Label.Text = "x"
27 p.Y.Label.Text = "f(x)"
28
29 f := plotter.NewFunction(math.Exp)
30 f.XMin = 0.2
31 f.XMax = 10
32
33 f.Color = color.RGBA{R: 255, A: 255}
34
35 p.Add(f, plotter.NewGrid())
36 p.Legend.Add("exp(x)", f)
37
38
39
40
41 p.X.Min = f.XMin
42 p.X.Max = f.XMax
43 p.Y.Min = math.Exp(f.XMin)
44 p.Y.Max = math.Exp(f.XMax)
45
46 err := p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/invertedlogscale.png")
47 if err != nil {
48 log.Panic(err)
49 }
50 }
51
View as plain text