-
Notifications
You must be signed in to change notification settings - Fork 1
Plot model cmdlets
In OxyPlot, series, axes and annotations are aggregated to a plot model to form a chart. A plot model is represented by the OxyPlot.PlotModel class.
Several cmdlets are defined to create, manipulate, and display a chart based on a plot model.
The New-OxyPlotModel cmdlet is a basic cmdlet to create an OxyPlot.PlotModel object. The Add-OxyObjectToPlotModel cmdlet can be used to add series, axes and annotations to a plot model. The Show-OxyPlot cmdlet takes a PlotModel object through pipeline, opens a window and plots a chart based on the plot model.
# Create a plot model
$model = New-OxyPlotModel
# Prepare series objects
$scatter = New-OxyScatterSeries
$axis = New-OxyLogarithmicAxis
# Add them to a plot model
Add-OxyObjectToPlotModel $scatter $model
Add-OxyObjectToPlotModel $axis $model
# Display a chart
$model | Show-OxyPlotThe New-OxyPlotModel accepts the -Show parameter to display a chart immediately.
# An empty window appears
$model = New-OxyPlotModel -ShowIn addition, object creation cmdlets, such as New-OxyLineSeries, provide the -AddTo parameter, which takes a plot model and adds a newly created object to it. When the -AddTo parameter is specified, the cmdlet returns no object, and the chart is updated immediately.
New-OxyLinearAxis -Position Bottom -AddTo $model
New-OxyScatterSeries -AddTo $modelBy using these parameters, you can build up a chart in an interactive way.
Furthermore, you can give series objects as input objects of New-OxyPlotModel or Show-OxyPlot.
$scatter = New-OxyScatterSeries
$line = New-OxyLineSeries
$model = $scatter, $line | New-OxyPlotModelYou can use Show-OxyPlot to plot a chart, if you don't need OxyPlot objects later. This is a way to plot a chart in one line.
oxyscat -X 1,2,3 -Y 4,5,6 | Show-OxyPlotThe Save-OxyPlot cmdlet works in a similar way to Show-OxyPlot, but saves the chart to an image file.
$model | Save-OxyPlot -OutFile chart.png -ImageWidth 800 -ImageHeight 600This cmdlet defines several parameters specific to image files: -OutFile, -ImageWidth, -ImageHeight, or -ImageBackground.
As the other object creation cmdlets, New-OxyPlotModel, Show-OxyPlot and Save-OxyPlot provides parameters for object properties.
First, these cmdlets accept OxyPlot.PlotModel properties as parameters. The following script creates a PlotModel object and sets the property Title to "Example Chart" (and plot a chart).
$line | Show-OxyPlot -Title "Example Chart"Secondly, they take a set of parameters that begin with -Ax or -Ay for axes.
The -AxType parameter specifies an axis class name for the X-axis of the plot model. The other parameters that begin with -Ax correspond to the properties of the axis object, prefixed with -Ax. For example, -AxTitle sets the value of the Title property of the axis object.
The -AxType parameter can recognize a partial name of a class. In the following example, the value log matches the class name OxyPlot.Axes.LogarithmicAxis, so that a log-scale axis will be chosen.
$model = New-OxyPlotModel -AxType log -AxTitle "X (in log scale)"This example is equivalent to the following script:
$axis = New-OxyLogarithmicAxis -Position Bottom -Title "X (in log scale)"
$model = New-OxyPlotModel
Add-OxyObjectToPlotModel $axis $modelThe -AyType and the other -Ay parameters are the same for the Y-axis of the plot model.