scatter

scatter{

x=, y=,

[name=DefaultName],

[title=""],

[xlab=""],

[ylab=""],

[marker={type="c", size=4, fill=DefaultColor, linewidth=1, linecolor=DefaultColor}],

[line={ color=DefaultColor, width=1, style="solid", smooth=false}],

[trendline={ type="linear", degree=2, intercept=AutoCompute, name=DefaultName, color=DefaultColor, width=1, style="dash"}]

[hwnd=nil],

} → window handle (light userdata)

 

The functions returns the window handle of the plot window. The data series (x, y) must be shown either by a marker or by a line or by both. If neither a marker nor a line is defined then a marker with default values will be shown. Once a data series is presented then a trendline can be shown.

 

Note on Terminology: The word Default in the arguments is used to denote that the so-called value is assigned/computed by the system until a new value is assigned.

 

Arguments:

x, y: x- and y-data ← Vector
name: Name of the series ← string
title: Title of the chart ← string
xlab: Label of x-axis ← string
ylab: Label of y-axis ← string
 
Marker Properties
type: "c", "t" or "s" for circle, triangle or square, respectively ← string
size: size of the marker ← integer
fill: fill color, in the form of “R G B” ← string
linewidth: width of the line forming the boundary of the marker ← integer
linecolor: color of the line, in the form of “R G B”, forming the boundary ← string
 
Line Properties
width: width of the line ← integer
color: color of the line, in the form of "R G B" ← string
style: "solid", "dash" or "dot" ← string
smooth: Spline algorithm is applied to smooth the line ← boolean
 
Trendline Properties
type: "exp", "linear", "log", "poly" and "pow" for exponential, linear, logarithmic, polynomial and power fitting, respectively. ← string
degree: If type="poly", then the degree of the polynomial ← integer
intercept: The desired intercept of the trendline ← number
color: color of the trendline, in the form of "R G B" ← string
width: width of the trendline ← integer
style: "solid", "dash" or "dot" ← string
 
hwnd: The handle of a window. If nil then the chart is displayed on a new plot window ← Light userdata

 

 

EXAMPLES

Let's start from simple to advanced use of the scatter command and let's stick to the same x and y data (arbitrarily chosen) and declare them beforehand as x and y are not optional.

>>x=std.tovector{1, 2, 3, 4}
>>y=std.tovector{1, 3, 7, 14}

 

A) Only data is provided: This is the simplest use of the command. The x- and y-data are provided, and the rest of the properties are provided by the system.

>>std.scatter{x=x, y=y} -- lets omit the returned windowID

The name of the series is automatically assigned as "Series 1" and since neither marker nor line is defined, by default the system will show a present x, y data pair by a marker with default values.

 

 

B) Define name and marker properties: The marker properties are fully customized.

>>std.scatter{x=x, y=y, name="xy data", marker={type="t", size=7, fill="255 0 0", linecolor="0 0 255", linewidth=2}}

Here, the name of the series is defined as "xy data", and the marker type is chosen to be triangle. Marker will be filled with red color and the boundary of the marker will be blue with a thickness of 2 pixels. Note that had we not defined the linecolor and linewidth, it would have assumed the fill color (red color). 

 

 

C) Define only line: Our objective is to show the data only with connected lines.

>>std.scatter{x=x, y=y, line={color="255 0 0", width=2}}

Please note that in the command we defined the line properties but have not defined the marker at all.
Since a property, such as line is already defined, the system will omit the marker and will present the data only with lines.

 

In the above figure the existence of multiple lines and their connections are apparently noticeable rather than observing a smooth "single" curve. If we want a smooth curve:

>>std.scatter{x=x, y=y, line={color="255 0 0", width=2, smooth=true}}

 

 

D) Define marker and line: Our goal is to show the data with both lines and markers.

>>std.scatter{x=x, y=y, marker={type="s", size=6, fill="255 0 0"}, line={width=2}}

 

 

E) Adding Trendlines: The simplest way of adding trendline is just by defining the trendline property remembering that if we neither define marker nor line, by default marker will be shown.

>>std.scatter{x=x, y=y, trendline={type="poly", degree=3, color="255 0 0", intercept=-10}}

A 3rd degree polynomial trendline with a red color is shown and note that the marker color and properties are assigned by the system since we have not explicitly defined the marker properties.