Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create and plot a ContourSeries with Oxyplot?

I have a WPF application where I need to visualize y = y(x1, x2) where x1, x2 are linear coordinates. I can do this using the HeatMapSeries in Oxyplot, but when I want to plot two sets of data in the same window, heatmaps are not the proper tool. A couple of contour series would be better. Now, I have tried to achieve this in the same manner as with the HeatMapSeries, that worked pretty well:

public void PlotHeatMap (){

   OxyPlot.PlotModel model = new PlotModel { Title = "2-D data" };
   model.Axes.Add( new OxyPlot.Axes.LinearColorAxis { 
   Position = OxyPlot.Axes.AxisPosition.Right, 
   Palette = OxyPalettes.Jet( 500 ), 
   HighColor = OxyColors.Gray, 
   LowColor = OxyColors.Black } );

   OxyPlot.Series.HeatMapSeries heatmap = new OxyPlot.Series.HeatMapSeries {
     Data = ( Double[ , ] )data,
     X0 = x1min,
     X1 = x1max,
     Y0 = x2min,
     Y1 = x2max
    };

   model.Series.Add( heatmap );
}

Output from the HeatMapSeries

Now, when I try to use the ContourSeries instead, I just replace the HeatMapSeries with a ContourSeries:

public void PlotContour (){

   OxyPlot.PlotModel model = new PlotModel { Title = "2-D data" };
   model.Axes.Add( new OxyPlot.Axes.LinearColorAxis { 
   Position = OxyPlot.Axes.AxisPosition.Right, 
   Palette = OxyPalettes.Jet( 500 ), 
   HighColor = OxyColors.Gray, 
   LowColor = OxyColors.Black } );

   OxyPlot.Series.ContourSeries contour = new OxyPlot.Series.ContourSeries {
      ColumnCoordinates = arrayFromMinToMax1,
      RowCoordinates = arrayFromMinToMax2,
      ContourLevels = arrayOfLevels,
      ContourColors = arrayOfColors, // Same # elements as the levels' array
      Data = ( Double[ , ] )data
    };

   model.Series.Add( contour );
}

This just produce the output:

Output from the ContourSeries attempt

The x- and y-axes are there, and match the min and max coordinates, but I can see no contour lines. I suspect that there is something missing with setting up the Axis (should it be the same as for the HeatMapSeries??). I don't know how to proceed with this contour plot. Are there examples other than e.g. the ContourSeriesExamples at GitHub?

Thanks for any help!

like image 471
Mats Isaksson Avatar asked May 18 '15 13:05

Mats Isaksson


1 Answers

I finally found what was wrong - it was my mistake! The ColumnCoordinates and the RowCoordinates arrays must match the size of the DoubleArray Data! And I didn't make sure they were. Now the contour and heatmap align! Thanks Anders for support and pushing me into my own code!

HeatMap with Contour

like image 182
Mats Isaksson Avatar answered Nov 18 '22 02:11

Mats Isaksson