Advertisement
Artem_Chepurov

Oxyplot

Dec 15th, 2022
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Documents;
  7. using OxyPlot;
  8. using OxyPlot.Axes;
  9. using OxyPlot.Series;
  10.  
  11. namespace WpfAppSandbox
  12. {
  13.     public class MainViewModel
  14.     {
  15.         public MainViewModel()
  16.         {
  17.             this.MyModel = new PlotModel { Title = "Heatmap" };
  18.  
  19.             // Color axis (the X and Y axes are generated automatically)
  20.             this.MyModel.Axes.Add(new LinearColorAxis
  21.             {
  22.                 Palette = OxyPalettes.Rainbow(100)
  23.             });
  24.  
  25.             // generate 1d normal distribution
  26.             var singleData = new double[100];
  27.             for (int x = 0; x < 100; ++x)
  28.             {
  29.                 singleData[x] = Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0));
  30.             }
  31.  
  32.             // generate 2d normal distribution
  33.             var data = new double[100, 100];
  34.             for (int x = 0; x < 100; ++x)
  35.             {
  36.                 for (int y = 0; y < 100; ++y)
  37.                 {
  38.                     data[y, x] = singleData[x] * singleData[(y + 30) % 100] * 100;
  39.                 }
  40.             }
  41.  
  42.             List<OxyColor> colorList = new List<OxyColor>
  43.             {
  44.                 OxyColor.FromRgb(255, 0, 0),
  45.                 OxyColor.FromRgb(255, 128, 0),
  46.                 OxyColor.FromRgb(255, 255, 0),
  47.                 OxyColor.FromRgb(128, 255, 0),
  48.                 OxyColor.FromRgb(0, 255, 0),
  49.                 OxyColor.FromRgb(0, 255, 128),
  50.                 OxyColor.FromRgb(0, 255, 255),
  51.                 OxyColor.FromRgb(0, 128, 255),
  52.                 OxyColor.FromRgb(0, 0, 255)
  53.             };
  54.             var colormas = colorList.ToArray();
  55.             OxyPalette palette = new OxyPalette(colorList);
  56.  
  57.             var heatMapSeries = new HeatMapSeries
  58.             {
  59.                 X0 = 0,
  60.                 X1 = 99,
  61.                 Y0 = 0,
  62.                 Y1 = 99,
  63.                 //замыливает
  64.                 RenderMethod = HeatMapRenderMethod.Bitmap,
  65.                 Data = data,
  66.                 ColorAxisKey = "Z"
  67.             };
  68.  
  69.             this.MyModel.Axes.Add(new LinearColorAxis
  70.             {
  71.                 Key = "Z",
  72.                 Palette = OxyPalette.Interpolate(255, colormas),
  73.                 Position = AxisPosition.Right,
  74.                 //динамический интервал между черточками большими и маленькими
  75.                 IntervalLength = 15,
  76.                 //статический интервал между большими чертами со значением
  77.                 //MajorStep = 20,
  78.                 //статический интервал между маленкими чертами
  79.                 //MinorStep = 5,
  80.                 //длина главных черточек
  81.                 MajorTickSize = 15,
  82.                 //длина малых черточек
  83.                 MinorTickSize = 0
  84.  
  85.             });
  86.  
  87.             this.MyModel.Series.Add(heatMapSeries);
  88.         }
  89.  
  90.         public PlotModel MyModel { get; private set; }
  91.     }
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement