...

Source file src/gonum.org/v1/plot/vg/vgimg/vgimg_example_test.go

Documentation: gonum.org/v1/plot/vg/vgimg

     1  // Copyright ©2020 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 vgimg_test
     6  
     7  import (
     8  	"image"
     9  	"image/color"
    10  
    11  	"gonum.org/v1/plot"
    12  	"gonum.org/v1/plot/vg"
    13  	"gonum.org/v1/plot/vg/draw"
    14  	"gonum.org/v1/plot/vg/vgimg"
    15  )
    16  
    17  func ExampleUseDPI() {
    18  	p := plot.New()
    19  	p.Title.Text = "Title"
    20  	p.X.Label.Text = "X"
    21  	p.Y.Label.Text = "Y"
    22  
    23  	const (
    24  		width  = 10 * vg.Centimeter
    25  		height = 10 * vg.Centimeter
    26  	)
    27  
    28  	// Create a new canvas with the given dimensions,
    29  	// and specify an explicit DPI value (dot per inch)
    30  	// for the plot.
    31  	c := vgimg.NewWith(
    32  		vgimg.UseWH(width, height),
    33  		vgimg.UseDPI(72),
    34  	)
    35  
    36  	dc := draw.New(c)
    37  	p.Draw(dc)
    38  }
    39  
    40  func ExampleUseImage() {
    41  	p := plot.New()
    42  	p.Title.Text = "Title"
    43  	p.X.Label.Text = "X"
    44  	p.Y.Label.Text = "Y"
    45  
    46  	img := image.NewRGBA(image.Rect(0, 100, 0, 100))
    47  	// Create a new canvas using the given image to specify the dimensions
    48  	// of the plot.
    49  	//
    50  	// Note that modifications applied to the canvas will not be reflected on
    51  	// the input image.
    52  	c := vgimg.NewWith(
    53  		vgimg.UseImage(img),
    54  	)
    55  
    56  	dc := draw.New(c)
    57  	p.Draw(dc)
    58  }
    59  
    60  func ExampleUseBackgroundColor() {
    61  	p := plot.New()
    62  	p.Title.Text = "Title"
    63  	p.X.Label.Text = "X"
    64  	p.Y.Label.Text = "Y"
    65  
    66  	const (
    67  		width  = 10 * vg.Centimeter
    68  		height = 10 * vg.Centimeter
    69  	)
    70  
    71  	// Create a new canvas with the given dimensions,
    72  	// and specify an explicit background color for the plot.
    73  	c := vgimg.NewWith(
    74  		vgimg.UseWH(width, height),
    75  		vgimg.UseBackgroundColor(color.Transparent),
    76  	)
    77  
    78  	dc := draw.New(c)
    79  	p.Draw(dc)
    80  }
    81  

View as plain text