Scatter plots
A scatter plot is conceptually one of the simplest kinds of plots that can be produced with VectSharp.Plots. In a scatter plot, the data point are transformed into plot coordinates, and a “symbol” of some kind (e.g., a circle) is drawn at each point. A scatter plot can be produced using the Plot.Create.ScatterPlot
method; creating a scatter plot can be as simple as collecting some data and invoking this method:
This method has a few overloads, which make it possible to use different kinds of data (e.g., data stored as a double[][]
, Point[]
, (double, double)[]
). Each overload has a required parameter (the data to plot), and a number of optional parameters can be used to determine the appearance of some elements of the plot. Many of these are in common with other kinds of plots:
double width
: the width of the plot. Ignored if a customcoordinateSystem
is supplied.double height
: the height of the plot. Ignored if a customcoordinateSystem
is supplied.PlotElementPresentationAttributes axisPresentationAttributes
: the presentation attributes for the axes.double axisArrowSize
: the size for the arrows at the end of the axes.PlotElementPresentationAttributes axisLabelPresentationAttributes
: the presentation attributes for the labels on the axes.PlotElementPresentationAttributes axisTitlePresentationAttributes
: the presentation attributes for the axis titles.string xAxisTitle
: the title for the horizontal axis.string yAxisTitle
: the title for the vertical axis.string title
: the title for the plot.PlotElementPresentationAttributes titlePresentationAttributes
: the presentation attributes for the title of the plot.PlotElementPresentationAttributes gridPresentationAttributes
: the presentation attributes for the grid behind the data points.PlotElementPresentationAttributes dataPresentationAttributes
: the presentation attributes for the data points.double pointSize
: the size of the data points.IDataPointElement dataPointElement
: symbol used for each point (see the page describing theScatterPoints
plot element for more details).IContinuousInvertibleCoordinateSystem coordinateSystem
: the coordinate system used to get the point coordinates (if this is not supplied, a linear coordinate system is used).
Plotting multiple sets of points
The overloads of this method that take data as a IReadOnlyList<IReadOnlyList<IReadOnlyList<double>>>
(i.e., double[][][]
) or as a IReadOnlyList<IReadOnlyList<(double, double)>>
(i.e., (double, double)[][]
) can be used to plot multiple sets of data in the same plot with different appearances (e.g., colours, sizes, symbols, etc.). Some parameters are different for this methods:
IReadOnlyList<PlotElementPresentationAttributes> dataPresentationAttributes
IReadOnlyList<double> pointSizes
IReadOnlyList<IDataPointElement> dataPointElements
These are specified as lists (or arrays) instead of individual values, which makes it possible to specify a different value for each data set. If these arrays are shorter than the number of data sets, the values are wrapped (e.g., if only two pointSizes
are specified and 3 data sets are being plotted, the third data set will use the same point size as the first data set).
The following example shows the effects of some of these settings:
Adding trendlines
Additional elements can always be added to a Plot
; one element that you might wish to add to a scatter plot is a trendline. This can be done by creating a trendline object and using the Plot
object’s AddPlotElement
method to add the trendline to the plot. The following types of trendlines are currently implemented in VectSharp.Plots:
LinearTrendline
: a linear trendline ($y=a\cdot x+b$).ExponentialTrendLine
: an exponential trendline ($y=b\cdot\mathrm{e}^{a\cdot x}$).LogarithmicTrendLine
: a logarithmic trendline ($y=a\ln(x) + b$).PolynomialTrendLine
: a polynomial trendline of the specified degree $n$ ($y=\sum_{i = 0}^na_ix^i$).PowerLawTrendline
: a power law ($y = b\cdot x^a$).MovingAverageTrendLine
: a moving average with the specified period and weight function.
A trendline can be created either by specifying the parameters, or by providing the constructor with some data from which the parameters can be estimated (see the page describing them for more details). The following example shows how to add an exponential trendline and a linear trendline to the previous plot. Note that in a lin-log coordinate system, the linear trendline is curved and the exponential trendline is a straight line.
For more information about trendlines, see the page describing them.