go-hep.org/x/hep@v0.38.1/hplot/line_example_test.go (about)

     1  // Copyright ©2019 The go-hep 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 hplot_test
     6  
     7  import (
     8  	"image/color"
     9  	"log"
    10  
    11  	"go-hep.org/x/hep/hplot"
    12  	"gonum.org/v1/plot/vg"
    13  )
    14  
    15  // An example of making a vertical-line plot
    16  func ExampleVLine() {
    17  	p := hplot.New()
    18  	p.Title.Text = "vlines"
    19  	p.X.Min = 0
    20  	p.X.Max = 10
    21  	p.Y.Min = 0
    22  	p.Y.Max = 10
    23  
    24  	var (
    25  		left  = color.RGBA{B: 255, A: 255}
    26  		right = color.RGBA{R: 255, A: 255}
    27  	)
    28  
    29  	p.Add(
    30  		hplot.VLine(2.5, left, nil),
    31  		hplot.VLine(5, nil, nil),
    32  		hplot.VLine(7.5, nil, right),
    33  	)
    34  
    35  	err := p.Save(10*vg.Centimeter, -1, "testdata/vline.png")
    36  	if err != nil {
    37  		log.Fatalf("error: %+v", err)
    38  	}
    39  }
    40  
    41  // An example of making a horizontal-line plot
    42  func ExampleHLine() {
    43  	p := hplot.New()
    44  	p.Title.Text = "hlines"
    45  	p.X.Min = 0
    46  	p.X.Max = 10
    47  	p.Y.Min = 0
    48  	p.Y.Max = 10
    49  
    50  	var (
    51  		top    = color.RGBA{B: 255, A: 255}
    52  		bottom = color.RGBA{R: 255, A: 255}
    53  	)
    54  
    55  	p.Add(
    56  		hplot.HLine(2.5, nil, bottom),
    57  		hplot.HLine(5, nil, nil),
    58  		hplot.HLine(7.5, top, nil),
    59  	)
    60  
    61  	err := p.Save(10*vg.Centimeter, -1, "testdata/hline.png")
    62  	if err != nil {
    63  		log.Fatalf("error: %+v", err)
    64  	}
    65  }