OxyPlot Contour Series

1.4k views Asked by At

I want to make a contour plot from live x-y coordinate data (using OxyPlot).

I've seen the example given using the ContourSeries, and I'm having trouble understanding how to achieve the contours.

Here is the example code:

namespace ExampleLibrary
{
using System;

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

[Examples("ContourSeries"), Tags("Series")]
public class ContourSeriesExamples
{
    private static Func<double, double, double> peaks = (x, y) =>
           3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
           - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
           - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);

    [Example("Peaks")]
    public static PlotModel Peaks()
    {
        var model = new PlotModel { Title = "Peaks" };
        var cs = new ContourSeries
            {
                ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
                RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05)
            };
        cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
        model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
        model.Series.Add(cs);
        return model;
    }
}

Some of the things I don't understand are the 'peaks' math equation (what's its purpose, how is it derived?) And the other thing I don't understand is how the contour themselves are derived.

1

There are 1 answers

0
Jawad Sabir On

To understand "peaks", you need to be familiar with the general delegate Func<T, TResult>. In your example, the generate delegate "peaks" has two double inputs, and one output result as double also. The inputs are assumingly x and y. The output is the function after lambda "=>".

Regarding the second question; How the contour themselves are derived? You can imagine contours as 3D object drawn on plain XY Cartesian, at each x,y there is a value of z that is on the same plain.