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.
()
| 46 | // The Y-axis is instructed to automatically adapt its range according to |
| 47 | // the underlying Y-ticker. |
| 48 | func 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 | } |
nothing calls this directly
no test coverage detected