import "github.com/sksullivan/plot"
Package plot provides an API for setting up plots, and primitives for drawing on plots.
Plot is the basic type for creating a plot, setting the title, axis labels, legend, tick marks, etc. Types implementing the Plotter interface can draw to the data area of a plot using the primitives made available by this package. Some standard implementations of the Plotter interface can be found in the github.com/sksullivan/plot/plotter package which is documented here: http://godoc.org/github.com/sksullivan/plot/plotter
var ( // DefaultFont is the name of the default font for plot text. DefaultFont = "Times-Roman" )
type Axis struct { // Min and Max are the minimum and maximum data // values represented by the axis. Min, Max float64 Label struct { // Text is the axis label string. Text string // TextStyle is the style of the axis label text. draw.TextStyle } // LineStyle is the style of the axis line. draw.LineStyle // Padding between the axis line and the data. Having // non-zero padding ensures that the data is never drawn // on the axis, thus making it easier to see. Padding vg.Length Tick struct { // Label is the TextStyle on the tick labels. Label draw.TextStyle // LineStyle is the LineStyle of the tick lines. draw.LineStyle // Length is the length of a major tick mark. // Minor tick marks are half of the length of major // tick marks. Length vg.Length // Marker returns the tick marks. Any tick marks // returned by the Marker function that are not in // range of the axis are not drawn. Marker Ticker } // Scale transforms a value given in the data coordinate system // to the normalized coordinate system of the axis—its distance // along the axis as a fraction of the axis range. Scale Normalizer }
An Axis represents either a horizontal or vertical axis of a plot.
Norm returns the value of x, given in the data coordinate system, normalized to its distance as a fraction of the range of this axis. For example, if x is a.Min then the return value is 0, and if x is a.Max then the return value is 1.
ConstantTicks is suitable for the Tick.Marker field of an Axis. This function returns the given set of ticks.
func (ts ConstantTicks) Ticks(float64, float64) []Tick
Ticks returns Ticks in a specified range
type DataRanger interface { // DataRange returns the range of X and Y values. DataRange() (xmin, xmax, ymin, ymax float64) }
DataRanger wraps the DataRange method.
type DefaultTicks struct{}
DefaultTicks is suitable for the Tick.Marker field of an Axis, it returns a resonable default set of tick marks.
func (DefaultTicks) Ticks(min, max float64) (ticks []Tick)
Ticks returns Ticks in a specified range
type GlyphBox struct { // The glyph location in normalized coordinates. X, Y float64 // Rectangle is the offset of the glyph's minimum drawing // point relative to the glyph location and its size. draw.Rectangle }
A GlyphBox describes the location of a glyph and the offset/size of its bounding box.
If the Rectangle.Size().X is non-positive (<= 0) then the GlyphBox is ignored when computing the horizontal padding, and likewise with Rectangle.Size().Y and the vertical padding.
GlyphBoxer wraps the GlyphBoxes method. It should be implemented by things that meet the Plotter interface that draw glyphs so that their glyphs are not clipped if drawn near the edge of the draw.Canvas.
When computing padding, the plot ignores GlyphBoxes as follows: If the Size.X > 0 and the X value is not in range of the X axis then the box is ignored. If Size.Y > 0 and the Y value is not in range of the Y axis then the box is ignored.
Also, GlyphBoxes with Size.X <= 0 are ignored when computing horizontal padding and GlyphBoxes with Size.Y <= 0 are ignored when computing vertical padding. This is useful for things like box plots and bar charts where the boxes and bars are considered to be glyphs in the X direction (and thus need padding), but may be clipped in the Y direction (and do not need padding).
type Legend struct { // TextStyle is the style given to the legend // entry texts. draw.TextStyle // Padding is the amount of padding to add // betweeneach entry of the legend. If Padding // is zero then entries are spaced based on the // font size. Padding vg.Length // Top and Left specify the location of the legend. // If Top is true the legend is located along the top // edge of the plot, otherwise it is located along // the bottom edge. If Left is true then the legend // is located along the left edge of the plot, and the // text is positioned after the icons, otherwise it is // located along the right edge and the text is // positioned before the icons. Top, Left bool // XOffs and YOffs are added to the legend's // final position. XOffs, YOffs vg.Length // ThumbnailWidth is the width of legend thumbnails. ThumbnailWidth vg.Length // contains filtered or unexported fields }
A Legend gives a description of the meaning of different data elements of the plot. Each legend entry has a name and a thumbnail, where the thumbnail shows a small sample of the display style of the corresponding data.
func (l *Legend) Add(name string, thumbs ...Thumbnailer)
Add adds an entry to the legend with the given name. The entry's thumbnail is drawn as the composite of all of the thumbnails.
type LinearScale struct{}
LinearScale an be used as the value of an Axis.Scale function to set the axis to a standard linear scale.
func (LinearScale) Normalize(min, max, x float64) float64
type LogScale struct{}
LocScale can be used as the value of an Axis.Scale function to set the axis to a log scale.
type LogTicks struct{}
LogTicks is suitable for the Tick.Marker field of an Axis, it returns tick marks suitable for a log-scale axis.
Ticks returns Ticks in a specified range
type Normalizer interface { // Normalize transforms a value x in the data coordinate system to // the normalized coordinate system. Normalize(min, max, x float64) float64 }
Normalizer rescales values from the data coordinate system to the normalized coordinate system.
type Plot struct { Title struct { // Text is the text of the plot title. If // Text is the empty string then the plot // will not have a title. Text string // Padding is the amount of padding // between the bottom of the title and // the top of the plot. Padding vg.Length draw.TextStyle } // BackgroundColor is the background color of the plot. // The default is White. BackgroundColor color.Color // X and Y are the horizontal and vertical axes // of the plot respectively. X, Y Axis // Legend is the plot's legend. Legend Legend // contains filtered or unexported fields }
Plot is the basic type representing a plot.
New returns a new plot with some reasonable default settings.
Add adds a Plotters to the plot.
If the plotters implements DataRanger then the minimum and maximum values of the X and Y axes are changed if necessary to fit the range of the data.
When drawing the plot, Plotters are drawn in the order in which they were added to the plot.
DataCanvas returns a new draw.Canvas that is the subset of the given draw area into which the plot data will be drawn.
Draw draws a plot to a draw.Canvas.
Plotters are drawn in the order in which they were added to the plot. Plotters that implement the GlyphBoxer interface will have their GlyphBoxes taken into account when padding the plot so that none of their glyphs are clipped.
DrawGlyphBoxes draws red outlines around the plot's GlyphBoxes. This is intended for debugging.
GlyphBoxes returns the GlyphBoxes for all plot data that meet the GlyphBoxer interface.
HideAxes hides the X and Y axes.
HideX configures the X axis so that it will not be drawn.
HideY configures the Y axis so that it will not be drawn.
NominalX configures the plot to have a nominal X axis—an X axis with names instead of numbers. The X location corresponding to each name are the integers, e.g., the x value 0 is centered above the first name and 1 is above the second name, etc. Labels for x values that do not end up in range of the X axis will not have tick marks.
NominalY is like NominalX, but for the Y axis.
Save saves the plot to an image file. The file format is determined by the extension.
Supported extensions are:
.eps, .jpg, .jpeg, .pdf, .png, .svg, .tif and .tiff.
Transforms returns functions to transfrom from the x and y data coordinate system to the draw coordinate system of the given draw area.
WriterTo returns an io.WriterTo that will write the plot as the specified image format.
Supported formats are:
eps, jpg|jpeg, pdf, png, svg, and tif|tiff.
Plotter is an interface that wraps the Plot method. Some standard implementations of Plotter can be found in the github.com/sksullivan/plot/plotter package, documented here: http://godoc.org/github.com/sksullivan/plot/plotter
type Thumbnailer interface { // Thumbnail draws an thumbnail representing // a legend entry. The thumbnail will usually show // a smaller representation of the style used // to plot the corresponding data. Thumbnail(c *draw.Canvas) }
Thumbnailer wraps the Thumbnail method, which draws the small image in a legend representing the style of data.
type Tick struct { // Value is the data value marked by this Tick. Value float64 // Label is the text to display at the tick mark. // If Label is an empty string then this is a minor // tick mark. Label string }
A Tick is a single tick mark on an axis.
IsMinor returns true if this is a minor tick mark.
type Ticker interface { // Ticks returns Ticks in a specified range Ticks(min, max float64) []Tick }
Ticker creates Ticks in a specified range
Path | Synopsis |
---|---|
gob | |
palette | Package palette provides basic color palette handling. |
palette/brewer | Package brewer provides Brewer Palettes for informative graphics. |
plotter | Package plotter defines a variety of standard Plotters for the plot package. |
plotutil | Package plotutil contains a small number of utilites for creating plots. |
vg | Package vg defines an interface for drawing 2D vector graphics. |
vg/draw | |
vg/recorder | Package recorder provides support for vector graphics serialization. |
vg/vgeps | Package vgeps implements the vg.Canvas interface using encapsulated postscript. |
vg/vgimg | Package vgimg implements the vg.Canvas interface using draw2d (github.com/sksullivan/draw2d) as a backend to output raster images. |
vg/vgpdf | Package vgpdf implements the vg.Canvas interface using gopdf (bitbucket.org/zombiezen/gopdf/pdf). |
vg/vgsvg | Package vgsvg uses svgo (github.com/ajstarks/svgo) as a backend for vg. |
vg/vgx11 | Package vgx11 implements X-Window vg support. |
Package plot imports 15 packages (graph) and is imported by 3 packages. Updated 2016-08-04. Refresh now. Tools for package owners.