OxyPlotにHeatMapSeriesというのがある
OxyPlotにHeatMapSeriesというのがあるというのを知った.これまでは,Bitmapで自分で描いていた.
Bitmapで自分で描くより楽だ.例えばここのようなサンプルが良い.
下は参考ページのやり方・名前の取り方をほぼそのまま参照している.Windows Forms用に少し手直しが入っているのと,linearColorAxis1.Palette = OxyPalettes.Gray(10);を追加しているところくらいが異なる.(参考ではRainbowになっている?)
縦横に正弦波が0.5 秒おきに流れていく(感じ).
using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; using OxyPlot.WindowsForms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace HeatmapTest { private OxyPlot.WindowsForms.PlotView plotView1; private PlotModel plotModelSpectrogram = new PlotModel(); public HeatMapSeries heatMapSeries1 = new HeatMapSeries(); private Double[,] Data = new Double[240, 250]; private double t = 0; private System.Windows.Forms.Timer timer1; public Form1() { InitializeComponent(); this.plotView1 = new OxyPlot.WindowsForms.PlotView(); this.plotView1.Dock = System.Windows.Forms.DockStyle.Fill; this.plotView1.Location = new System.Drawing.Point(0, 0); this.plotView1.Name = "plotView1"; this.plotView1.PanCursor = System.Windows.Forms.Cursors.Hand; this.plotView1.Size = new System.Drawing.Size(633, 362); this.plotView1.TabIndex = 0; this.plotView1.Text = "plotView1"; this.plotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE; this.plotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE; this.plotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS; this.Controls.Add(this.plotView1); plotModelSpectrogram.Title = "TEST"; var linearColorAxis1 = new LinearColorAxis(); linearColorAxis1.Palette = OxyPalettes.Gray(10); linearColorAxis1.Position = AxisPosition.Right; linearColorAxis1.Minimum = 0.0; linearColorAxis1.Maximum = 100; plotModelSpectrogram.Axes.Add(linearColorAxis1); var linearAxis1 = new LinearAxis(); linearAxis1.Position = AxisPosition.Bottom; linearAxis1.IsAxisVisible = false; linearAxis1.IsZoomEnabled = false; plotModelSpectrogram.Axes.Add(linearAxis1); // Dummy var linearAxis_a = new LinearAxis(); linearAxis_a.Position = AxisPosition.Bottom; linearAxis_a.Minimum = 0.0; linearAxis_a.Maximum = 120.0; linearAxis_a.Title = "Time s"; linearAxis_a.IsZoomEnabled = false; plotModelSpectrogram.Axes.Add(linearAxis_a); var linearAxis2 = new LinearAxis(); linearAxis2.Position = AxisPosition.Left; linearAxis2.IsAxisVisible = false; linearAxis2.IsZoomEnabled = false; plotModelSpectrogram.Axes.Add(linearAxis2); // Dummy var linearAxis_b = new LinearAxis(); linearAxis_b.Position = AxisPosition.Left; linearAxis_b.Minimum = 0.0; linearAxis_b.Maximum = 1000.0; linearAxis_b.Title = "Frequency kHz"; linearAxis_b.IsZoomEnabled = false; plotModelSpectrogram.Axes.Add(linearAxis_b); heatMapSeries1.Data = new double[240, 250]; heatMapSeries1.X0 = 0.0; heatMapSeries1.X1 = 100.0; heatMapSeries1.Y0 = 0.0; heatMapSeries1.Y1 = 1000.0; plotModelSpectrogram.Series.Add(heatMapSeries1); this.plotView1.Model = plotModelSpectrogram; this.timer1 = new Timer(); this.timer1.Interval = 500; this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); } private void timer1_Tick(object sender, EventArgs e) { PlotSpectrogram(); } private void AddLastData(Double[] data) { for (int i = 0; i < Data.GetLength(0) - 1; i++) { for (int j = 0; j < Data.GetLength(1); j++) { Data[i, j] = Data[i + 1, j]; } } for (int j = 0; j < Data.GetLength(1); j++) { Data[Data.GetLength(0) - 1, j] = data[j]; } var pldata = new double[240, 250]; Array.Copy(Data, pldata, Data.Length); heatMapSeries1.Data = pldata; } public void PlotSpectrogram() { Double[] data = new Double[Data.GetLength(1)]; for (int i = 0; i < data.Length; i++) { data[i] = (50.0 + 20.0 * Math.Sin(0.2 * i) + 20.0 * Math.Sin(t)); } t += 0.5; AddLastData(data); plotModelSpectrogram.InvalidatePlot(true); } } }