A matplotlib-like plotting library: scatter, histogram, line and bar charts, subplots, as standalone SVG. A Figure holds one or more Axes; drawing the figure builds a PlotScene, an ordered list of pixel-space drawing primitives (lines, polylines, polygons, rects, circles, text), and a backend turns the scene into output. The SVG backend writes SVG 1.1 with no script and no external font, one decimal for every coordinate, so the same data gives the same bytes on every platform. Compile with -lib plot,gen_collect; it needs nothing else and draws without a display. Design: docs/PLOT_DESIGN.md. Examples: docs/AI.md, "Plotting".
PlotPrimitive
One drawing primitive in pixel space. Colors are CSS strings such as "#1f77b4"; an empty string means none. Which fields are meaningful depends on the kind: LINE uses x1, y1, x2, y2; POLYLINE and POLYGON use the x, y pairs of GetPoints(); RECT uses x1, y1 as the corner and x2, y2 as the width and height; CIRCLE uses x1, y1 as the center and x2 as the radius; TEXT uses x1, y1 as the anchor point; CLIP_BEGIN uses the same corner, width and height as RECT and clips what follows until the matching CLIP_END.
Operations
- New
- GetAnchor
- GetDash
- GetFill
- GetKind
- GetOpacity
- GetPoints
- GetRotation
- GetSize
- GetStroke
- GetTag
- GetText
- GetWidth
- GetX1
- GetX2
- GetY1
- GetY2
- IsBold
GetAnchor #
Text anchor.
method : public : GetAnchor() ~ TextAnchorReturn
| Type | Description |
|---|---|
| TextAnchor | where the text sits relative to x |
GetDash #
Dash pattern.
method : public : GetDash() ~ StringReturn
| Type | Description |
|---|---|
| String | an SVG dash array such as "4 3", or an empty string for solid |
GetFill #
Fill color, or the text color.
method : public : GetFill() ~ StringReturn
| Type | Description |
|---|---|
| String | a CSS color, or an empty string for none |
GetKind #
What the primitive draws.
method : public : GetKind() ~ PrimitiveKindReturn
| Type | Description |
|---|---|
| PrimitiveKind | the kind |
GetPoints #
The x, y pairs of a polyline or polygon.
method : public : GetPoints() ~ Float[]Return
| Type | Description |
|---|---|
| Float | alternating x and y, or Nil |
GetRotation #
Text rotation about the anchor.
method : public : GetRotation() ~ FloatReturn
| Type | Description |
|---|---|
| Float | degrees, counter-clockwise negative as in SVG |
GetStroke #
Outline color.
method : public : GetStroke() ~ StringReturn
| Type | Description |
|---|---|
| String | a CSS color, or an empty string for none |
GetTag #
What the primitive is: marker, bar, grid, tick, legend, and so on.
method : public : GetTag() ~ StringReturn
| Type | Description |
|---|---|
| String | the tag |
GetText #
The string of a text primitive.
method : public : GetText() ~ StringReturn
| Type | Description |
|---|---|
| String | the text |
GetX1 #
First x, the corner or center x or the text anchor x.
method : public : GetX1() ~ FloatReturn
| Type | Description |
|---|---|
| Float | x |
GetX2 #
Second x of a line, the width of a rect or the radius of a circle.
method : public : GetX2() ~ FloatReturn
| Type | Description |
|---|---|
| Float | the value |
GetY2 #
Second y of a line or the height of a rect.
method : public : GetY2() ~ FloatReturn
| Type | Description |
|---|---|
| Float | the value |
IsBold #
Whether text is bold.
method : public : IsBold() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true for bold |
New # constructor
Constructor; PlotScene builds primitives, so most programs never call it.
New(kind:PrimitiveKind, x1:Float, y1:Float, x2:Float, y2:Float, points:Float[], stroke:String, fill:String, width:Float, opacity:Float, text:String, anchor:TextAnchor, size:Int, bold:Bool, rotation:Float, dash:String, tag:String)Parameters
| Name | Type | Description |
|---|---|---|
| kind | PrimitiveKind | what to draw |
| x1 | Float | first x |
| y1 | Float | first y |
| x2 | Float | second x, or width, or radius |
| y2 | Float | second y or height |
| points | Float | x, y pairs for a polyline or polygon, or Nil |
| stroke | String | outline color, or empty |
| fill | String | fill color, or empty |
| width | Float | stroke width in pixels |
| opacity | Float | fill opacity from 0 to 1 |
| text | String | the string of a text primitive |
| anchor | TextAnchor | text anchor |
| size | Int | text size in pixels |
| bold | Bool | true for bold text |
| rotation | Float | text rotation in degrees about its anchor |
| dash | String | SVG dash pattern such as "4 3", or empty |
| tag | String | what the primitive is (marker, bar, grid, ...), for tests and backends |