首页 文章

如何使用Oxyplot创建和绘制ContourSeries?

提问于
浏览
8

我有一个WPF应用程序,我需要可视化y = y(x1,x2),其中x1,x2是线性坐标 . 我可以使用Oxyplot中的HeatMapSeries来做到这一点,但是当我想在同一个窗口中绘制两组数据时,热图不是合适的工具 . 一些轮廓系列会更好 . 现在,我尝试以与HeatMapSeries相同的方式实现这一点,这非常有效:

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

现在,当我尝试使用ContourSeries时,我只是用一个ContourSeries替换HeatMapSeries:

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 );
}

这只是产生输出:

Output from the ContourSeries attempt

x轴和y轴在那里,并匹配最小和最大坐标,但我看不到轮廓线 . 我怀疑设置轴时缺少一些东西(它应该与HeatMapSeries相同吗?) . 我不知道如何继续这个轮廓图 . 有除例如以外的例子吗? GitHub上的ContourSeriesExamples?

谢谢你的帮助!

1 回答

  • 2

    我终于找到了什么错 - 这是我的错! ColumnCoordinatesRowCoordinates 数组必须与DoubleArray Data 的大小相匹配!我没有确定他们是谁 . 现在轮廓和热图对齐!感谢Anders的支持并将我推向我自己的代码!

    HeatMap with Contour

相关问题