...

Source file src/gonum.org/v1/plot/plotter/filledLine_example_test.go

Documentation: gonum.org/v1/plot/plotter

     1  // Copyright ©2018 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package plotter_test
     6  
     7  import (
     8  	"image/color"
     9  	"log"
    10  
    11  	"golang.org/x/exp/rand"
    12  
    13  	"gonum.org/v1/plot"
    14  	"gonum.org/v1/plot/plotter"
    15  )
    16  
    17  func ExampleLine_filledLine() {
    18  	rnd := rand.New(rand.NewSource(1))
    19  
    20  	// randomPoints returns some random x, y points
    21  	// with some interesting kind of trend.
    22  	randomPoints := func(n int, x float64) plotter.XYs {
    23  		pts := make(plotter.XYs, n)
    24  		for i := range pts {
    25  			if i == 0 {
    26  				pts[i].X = x + rnd.Float64()
    27  			} else {
    28  				pts[i].X = pts[i-1].X + 0.5 + rnd.Float64()
    29  			}
    30  			pts[i].Y = -5. + 10*rnd.Float64()
    31  		}
    32  		return pts
    33  	}
    34  
    35  	p := plot.New()
    36  	p.Title.Text = "Filled Line Example"
    37  	p.X.Label.Text = "X"
    38  	p.Y.Label.Text = "Y"
    39  	p.Add(plotter.NewGrid())
    40  
    41  	filled, err := plotter.NewLine(randomPoints(4, 0))
    42  	if err != nil {
    43  		log.Panic(err)
    44  	}
    45  	filled.FillColor = color.RGBA{R: 196, G: 255, B: 196, A: 255}
    46  
    47  	p.Add(filled)
    48  
    49  	err = p.Save(200, 200, "testdata/filledLine.png")
    50  	if err != nil {
    51  		log.Panic(err)
    52  	}
    53  }
    54  

View as plain text