Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Series;
- namespace WpfAppSandbox
- {
- public class MainViewModel
- {
- public MainViewModel()
- {
- this.MyModel = new PlotModel { Title = "Heatmap" };
- // Color axis (the X and Y axes are generated automatically)
- this.MyModel.Axes.Add(new LinearColorAxis
- {
- Palette = OxyPalettes.Rainbow(100)
- });
- // generate 1d normal distribution
- var singleData = new double[100];
- for (int x = 0; x < 100; ++x)
- {
- singleData[x] = Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0));
- }
- // generate 2d normal distribution
- var data = new double[100, 100];
- for (int x = 0; x < 100; ++x)
- {
- for (int y = 0; y < 100; ++y)
- {
- data[y, x] = singleData[x] * singleData[(y + 30) % 100] * 100;
- }
- }
- List<OxyColor> colorList = new List<OxyColor>
- {
- OxyColor.FromRgb(255, 0, 0),
- OxyColor.FromRgb(255, 128, 0),
- OxyColor.FromRgb(255, 255, 0),
- OxyColor.FromRgb(128, 255, 0),
- OxyColor.FromRgb(0, 255, 0),
- OxyColor.FromRgb(0, 255, 128),
- OxyColor.FromRgb(0, 255, 255),
- OxyColor.FromRgb(0, 128, 255),
- OxyColor.FromRgb(0, 0, 255)
- };
- var colormas = colorList.ToArray();
- OxyPalette palette = new OxyPalette(colorList);
- var heatMapSeries = new HeatMapSeries
- {
- X0 = 0,
- X1 = 99,
- Y0 = 0,
- Y1 = 99,
- //замыливает
- RenderMethod = HeatMapRenderMethod.Bitmap,
- Data = data,
- ColorAxisKey = "Z"
- };
- this.MyModel.Axes.Add(new LinearColorAxis
- {
- Key = "Z",
- Palette = OxyPalette.Interpolate(255, colormas),
- Position = AxisPosition.Right,
- //динамический интервал между черточками большими и маленькими
- IntervalLength = 15,
- //статический интервал между большими чертами со значением
- //MajorStep = 20,
- //статический интервал между маленкими чертами
- //MinorStep = 5,
- //длина главных черточек
- MajorTickSize = 15,
- //длина малых черточек
- MinorTickSize = 0
- });
- this.MyModel.Series.Add(heatMapSeries);
- }
- public PlotModel MyModel { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement