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

Function Example_logScaleWithAutoRescale

plotter/logscale_example_test.go:48–74  ·  view source on GitHub ↗

Example_logScaleWithAutoRescale shows how to create a plot with a log-scale on the Y-axis. The Y-axis is instructed to automatically adapt its range according to the underlying Y-ticker.

()

Source from the content-addressed store, hash-verified

46// The Y-axis is instructed to automatically adapt its range according to
47// the underlying Y-ticker.
48func Example_logScaleWithAutoRescale() {
49 p := plot.New()
50 p.Title.Text = "My Plot"
51 p.Y.Scale = plot.LogScale{}
52 p.Y.Tick.Marker = plot.LogTicks{Prec: -1}
53 p.Y.AutoRescale = true
54 p.X.Label.Text = "x"
55 p.Y.Label.Text = "f(x)"
56
57 f := plotter.NewFunction(math.Exp)
58 f.XMin = 0.2
59 f.XMax = 10
60 f.Color = color.RGBA{R: 255, A: 255}
61
62 p.Add(f, plotter.NewGrid())
63 p.Legend.Add("exp(x)", f)
64
65 p.X.Min = f.XMin
66 p.X.Max = f.XMax
67 p.Y.Min = math.Exp(f.XMin)
68 p.Y.Max = math.Exp(f.XMax)
69
70 err := p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/logscale_autorescale.png")
71 if err != nil {
72 log.Panic(err)
73 }
74}

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