MCPcopy Index your code
hub / github.com/gonum/plot / Example_invertedScale

Function Example_invertedScale

plotter/invertedaxis_example_test.go:17–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func Example_invertedScale() {
18 // This example is nearly identical to the LogScale, other than
19 // both the X and Y axes are inverted. InvertedScale expects to act
20 // on another Normalizer - which should allow for more flexibility
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 // Neither .Min nor .Max for the X and Y axes are 'swapped'.
39 // The minimal value is retained in .Min, and the maximal
40 // value stays in .Max.
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}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
NewFunctionFunction · 0.92
NewGridFunction · 0.92
SaveMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected