public static PlotModel RectangleBarSeries() { var model = new PlotModel("RectangleBarSeries") { LegendPlacement = LegendPlacement.Outside }; var s1 = new RectangleBarSeries { Title = "RectangleBarSeries 1" }; s1.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = 1, Y1 = 4 }); s1.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = 6, Y1 = 7 }); model.Series.Add(s1); var s2 = new RectangleBarSeries { Title = "RectangleBarSeries 2" }; s2.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = -4, Y1 = -1 }); s2.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = -7, Y1 = -6 }); model.Series.Add(s2); return(model); }
public override void AddToModel(PlotModel model) { if (dType == ModelDisplayType.Line) { LineSeries lser = new LineSeries(this.lineName); List <DataPoint> lxy = GetHistoCoords(); foreach (DataPoint xy in lxy) { lser.Points.Add(xy); } lser.Smooth = true; model.Series.Add(lser); } else if (dType == ModelDisplayType.Bar) { RectangleBarSeries inSeries = new RectangleBarSeries(); inSeries.Title = this.lineName; List <RectangleBarItem> lrect = GetHistoBars(); foreach (RectangleBarItem r in lrect) { inSeries.Items.Add(r); } model.Series.Add(inSeries); } }
private void _plotData(PlotView plot, IEnumerable <ProductTask> tasks) { var lastTask = tasks.Last(); var totalTime = lastTask.StartTime.Last() + lastTask.TimeOnBench.Last(); var model = new PlotModel { Title = "Total time = " + totalTime, LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.LeftTop, }; foreach (var task in tasks) { var taskSeries = new RectangleBarSeries { Title = "Task" + task.Number }; for (int i = 0; i < task.TimeOnBench.Length; i++) { taskSeries.Items.Add(new RectangleBarItem { X0 = task.StartTime[i], X1 = task.StartTime[i] + task.TimeOnBench[i], Y0 = 0 + i, Y1 = 1 + i, Title = task.TimeOnBench[i].ToString() }); } model.Series.Add(taskSeries); } plot.Model = model; }
public List <Series> GetNextSeries(string addIt) { List <Series> srl = new List <Series> (); if (dType == ModelDisplayType.Line) { LineSeries lser = new LineSeries(addIt + this.lineName); List <DataPoint> lxy = GetHistoCoords(); foreach (DataPoint xy in lxy) { lser.Points.Add(xy); } lser.Smooth = true; srl.Add(lser); } else if (dType == ModelDisplayType.Bar) { RectangleBarSeries inSeries = new RectangleBarSeries(); inSeries.Title = addIt + this.lineName; List <RectangleBarItem> lrect = GetHistoBars(); foreach (RectangleBarItem r in lrect) { inSeries.Items.Add(r); } srl.Add(inSeries); } return(srl); }
public void PopulateBins(IEnumerable <double> samples, int numBins, string title) { var max = samples.Max(); var min = samples.Min(); var step = (max - min) / Convert.ToDouble(numBins); var binRange = Range.Double(min, max, step); var model = new PlotModel(title) { }; var s1 = new RectangleBarSeries { FillColor = OxyColors.CornflowerBlue }; foreach (var binMin in binRange) { var binMax = binMin + step; var binSamples = samples.Where(v => binMin <= v && v < binMax); var binCount = Convert.ToDouble(binSamples.Count()); s1.Items.Add(new RectangleBarItem { X0 = binMin, X1 = binMax, Y0 = 0, Y1 = binCount, }); } model.Series.Add(s1); model.PlotMargins = new OxyThickness(0, 30, 0, 0); var xMin = s1.Items.Min(b => b.X0); var xMax = s1.Items.Max(b => b.X1); if (xMin < xMax) { var xAxis = new LinearAxis(AxisPosition.Bottom, xMin, xMax, "Value"); xAxis.AbsoluteMinimum = xMin; xAxis.AbsoluteMaximum = xMax; xAxis.SetColors(); model.Axes.Add(xAxis); } var yMin = s1.Items.Min(b => b.Y0); var yMax = s1.Items.Max(b => b.Y1); if (yMin < yMax) { var yAxis = new LinearAxis(AxisPosition.Left, s1.Items.Min(b => b.Y0), s1.Items.Max(b => b.Y1), "Frequency"); yAxis.AbsoluteMinimum = s1.Items.Min(b => b.Y0); yAxis.AbsoluteMaximum = s1.Items.Max(b => b.Y1); yAxis.SetColors(); model.Axes.Add(yAxis); } model.SetColors(); HistogramModel = model; }
private void PlotResults() { try { var model = new PlotModel { Title = "Bytes frequency histogram", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }; OxyPlot.Series.RectangleBarSeries bars = new RectangleBarSeries(); if (_plotScale == PlotScale.Log) { throw new NotImplementedException("Logarithmic scale"); /*Axis yAxis = new LogarithmicAxis(); * model.Axes.Add(yAxis); * yAxis.AbsoluteMinimum = 0; * yAxis.Minimum = 0;*/ } for (int i = 0; i < _results.Length; i++) { double height = GetHeight(i); //HighLowItem chartItem = new HighLowItem(i, height, 0); RectangleBarItem item = new RectangleBarItem(i, 0, i + 1, height); bars.Items.Add(item); } model.Series.Add(bars); //model.Axes.Add(yAxis); HistogramDrawer.Model = model; HistogramDrawer.Visible = true; EntropyValueLabel.Text = _results.Entropy.ToString("0.00000"); ProcessUi(); } catch (NotImplementedException e) { MessageBox.Show("This feature is not implemented: " + e.Message); } catch (Exception e) { MessageBox.Show(e.Message); throw; } }
public RectangleBarSeries GetBarSeries() { var barSeries = new RectangleBarSeries(); //barSeries.PlotModel = PlotModel(); //barSeries.XAxis.PlotModel = PlotModel(); barItems = new List<RectangleBarItem>(); for (int i = 0; i < negativeBins.Count(); i++) { var item = (new RectangleBarItem(){ X0 = i * this.binSize, X1 = (i + 1) * binSize, Y0 =0, Y1 = negativeBins[i] , Color = OxyColors.BlueViolet, Title = "Title"}); barItems.Add(item); } barSeries.ItemsSource = barItems; return barSeries; }
Task RenderRectangleBar(Series plot) { var rectangleBarSeries = new RectangleBarSeries { Title = plot.Config.Title }; foreach (var item in plot.Data) { rectangleBarSeries.Items.Add(new RectangleBarItem(item.X0, item.Y0, item.X1, item.Y1)); } OxyplotModel.Series.Add(rectangleBarSeries); return(Task.CompletedTask); }
/// <summary> /// Populate timeline with some data - Here just some random data, later from the ADM model /// </summary> private void PopulateTimeline() { var rectangleBarSeries1 = new RectangleBarSeries(); rectangleBarSeries1.Title = "RectangleBarSeries 1"; rectangleBarSeries1.Items.Add(new RectangleBarItem(2, 1, 8, 4)); rectangleBarSeries1.Items.Add(new RectangleBarItem(6, 6, 12, 7)); model.Series.Add(rectangleBarSeries1); var rectangleBarSeries2 = new RectangleBarSeries(); rectangleBarSeries2.Title = "RectangleBarSeries 2"; rectangleBarSeries2.Items.Add(new RectangleBarItem(2, -4, 8, -1)); rectangleBarSeries2.Items.Add(new RectangleBarItem(6, -7, 12, -6)); model.Series.Add(rectangleBarSeries2); }
public static PlotModel RectangleBarSeries() { var model = new PlotModel { Title = "RectangleBarSeries", LegendPlacement = LegendPlacement.Outside }; var s1 = new RectangleBarSeries { Title = "RectangleBarSeries 1" }; s1.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = 1, Y1 = 4 }); s1.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = 6, Y1 = 7 }); model.Series.Add(s1); var s2 = new RectangleBarSeries { Title = "RectangleBarSeries 2" }; s2.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = -4, Y1 = -1 }); s2.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = -7, Y1 = -6 }); model.Series.Add(s2); return model; }
private RectangleBarSeries CreateHistogramSeries() { RectangleBarSeries series = new RectangleBarSeries() { StrokeThickness = 2.0 }; foreach (Histogram.Bin bin in Histogram.Bins) { if (bin.Count > 0) // Skip drawing a bar with a count of 0 { series.Items.Add(CreateBar(bin)); } } return(series); }
/// <summary> /// Creates a model showing normal distributions. /// </summary> /// <returns>A PlotModel.</returns> public async void CreateDiagram() { // Create Series var s1 = new RectangleBarSeries { Title = "Individual", }; var s2 = new RectangleBarSeries { Title = "Composite WhenAll" }; var s3 = new RectangleBarSeries { Title = "Composite WhenAny" }; // Create Tasks var simpleTask1 = Task.Delay(500).TrackTask(s1); var simpleTask2 = Task.Delay(250).TrackTask(s1); var simpleTask3 = Task.Delay(700).TrackTask(s1); var continuation1 = simpleTask1 .ContinueWith(t => Task.Delay(400).TrackTask(s1).Wait()) .TrackTask(s2, "first continuation"); var continuation2 = continuation1 .ContinueWith(t => Task.Delay(256).TrackTask(s1).Wait()) .TrackTask(s2, "second continuation"); Task.WhenAny(simpleTask1, simpleTask2, continuation1, continuation2) .TrackTask(s3, "When Any") .Ignore(); Task.WhenAll(simpleTask1, simpleTask2, continuation1, continuation2) .TrackTask(s2, "When All") .Ignore(); Task.WhenAll(simpleTask2, simpleTask3) .TrackTask(s2, $"When {nameof(simpleTask2)} and {nameof(simpleTask3)}") .Ignore(); PlotTaskExtensions.Unblock(); // Ensure all tasks completed and build the model. await Task.WhenAll(PlotTaskExtensions.AllTasks); this.Model = CreateModelFromSeries(s1, s2, s3); }
public static async Task TrackTask(this Task task, RectangleBarSeries series, string title = null) { await barrier.Task; var p0 = DateTime.Now; taskList.Add(task); await task; var pc = DateTime.Now; series.Items.Add(new RectangleBarItem(p0.ToOADate(), counter, pc.ToOADate(), counter + 1) { Title = title }); counter = counter + 1.25; }
public static PlotModel RectangleBarSeriesRenderedOnTopLayer() { var plotModel1 = new PlotModel { Title = "Issue 10236", }; var lineSeries1 = new LineSeries(); lineSeries1.Points.Add(new DataPoint(0, 1)); lineSeries1.Points.Add(new DataPoint(1, 0)); plotModel1.Series.Add(lineSeries1); var rectangleBarSeries1 = new RectangleBarSeries(); rectangleBarSeries1.Items.Add(new RectangleBarItem(0.25, 0.25, 0.75, 0.75)); plotModel1.Series.Add(rectangleBarSeries1); var lineSeries2 = new LineSeries(); lineSeries2.Points.Add(new DataPoint(0, 0)); lineSeries2.Points.Add(new DataPoint(1, 1)); plotModel1.Series.Add(lineSeries2); return(plotModel1); }
public void AddSeries(RectangleBarSeries b) { plot.Series.Add(b); this.Root.Model = plot; }
/// <summary> /// Plot calculated distribution with OxyPlot (type 0-null 1-size 2-area 3-combined) /// </summary> /// <param name="categ">categorized information CalBlobAC</param> /// <param name="type">0-null 1-size 2-area 3-combined</param> /// <returns></returns> public static PlotModel ToOxyPlot(this CalPAC categ, int type) { try { var plot = new PlotModel(); switch (type) { case 1: plot.Subtitle = $"Size Distribution\n{categ.Grouping} (N={categ.N})"; break; case 2: plot.Subtitle = $"Area Distribution\n{categ.Grouping} (N={categ.N})"; break; case 3: plot.Subtitle = $"Size & Area-Weighted Size Distribution\n{categ.Grouping} (N={categ.N})"; break; default: plot.Subtitle = ""; break; } plot.Axes.Add(new LinearAxis { Title = "Airspace log10 µm\xB2", Position = AxisPosition.Bottom, Minimum = 0, Maximum = 7, MajorStep = 1, MinorStep = 0.25, TickStyle = TickStyle.Inside }); plot.Axes.Add(new LinearAxis { Title = "Density", Position = AxisPosition.Left, Minimum = 0, Maximum = 1, MajorStep = 0.2, MinorStep = 0.05, TickStyle = TickStyle.Inside }); var fillsize = OxyColor.FromArgb(130, 0, 0, 230); var fillarea = OxyColor.FromArgb(130, 225, 19, 2); var outline = OxyColor.FromArgb(160, 0, 0, 0); var draw1 = OxyColor.FromArgb(255, 79, 154, 6); var draw2 = OxyColor.FromArgb(255, 220, 158, 30); var draw3 = OxyColor.FromArgb(255, 204, 0, 0); double width = 0.05; double offset = 0.05; if (type == 1 || type == 3) // size { var histogram = new RectangleBarSeries() { Title = $"Size Dist (LogLikelihood={categ.gmm1Fit:G2})", FillColor = fillsize, StrokeColor = outline }; for (int i = 0; i < categ.DistCount.Count; i++) { histogram.Items.Add(new RectangleBarItem(categ.DistCount[i][0] - width - offset, 0, categ.DistCount[i][0] + width - offset, categ.DistCount[i][1])); } plot.Series.Add(histogram); plot.Series.Add(FormGaussian($"Population 1 (µ={categ.p1Mean:0.00}, σ={categ.p1Covariance:0.00}, λ={categ.p1Proportion:0.00})", draw1, 0, 10, categ.p1Mean, categ.p1Covariance, categ.p1Proportion)); plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c1_DucDes_CI95_1tail, Text = $"x={categ.c1_DucDes_CI95_1tail:0.0}", Color = fillsize, StrokeThickness = 2 }); } if (type == 2 || type == 3) // area { var histogram = new RectangleBarSeries() { Title = $"Area-Weighted Size Dist (LogLikelihood={categ.gmm2Fit:G2})", FillColor = fillarea, StrokeColor = outline }; for (int i = 0; i < categ.DistArea.Count; i++) { histogram.Items.Add(new RectangleBarItem(categ.DistArea[i][0] - width + offset, 0, categ.DistArea[i][0] + width + offset, categ.DistArea[i][1])); } plot.Series.Add(histogram); plot.Series.Add(FormGaussian($"Population 2 (µ={categ.p2Mean:0.00}, σ={categ.p2Covariance:0.00}, λ={categ.p2Proportion:0.00})", draw2, 0, 10, categ.p2Mean, categ.p2Covariance, categ.p2Proportion)); plot.Series.Add(FormGaussian($"Population 3 (µ={categ.p3Mean:0.00}, σ={categ.p3Covariance:0.00}, λ={categ.p3Proportion:0.00})", draw3, 0, 10, categ.p3Mean, categ.p3Covariance, categ.p3Proportion)); if (type == 3) { plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c2_Sac_Log_Threshold, Text = $"x={categ.c2_Sac_Log_Threshold:0.0}", Color = OxyColor.FromArgb(130, 220, 158, 30), StrokeThickness = 2 }); } plot.Annotations.Add(new LineAnnotation() { Type = LineAnnotationType.Vertical, X = categ.c2_DucDes_Log_Threshold, Text = $"x={categ.c2_DucDes_Log_Threshold:0.0}", Color = fillarea, StrokeThickness = 2 }); } return(plot); } catch { throw new Exception("Error encountered generating histogram and distribution graph."); } }
/// <summary> /// Adds a histogram. The data X value is used to bin the data. /// </summary> public void AddHistogram(IEnumerable <Datum> data, int numBins, OxyColor?borderColor = null, OxyColor?fillColor = null, double borderThickness = 1, string xAxisLabel = null, string chartTitle = null, string chartSubtitle = null, bool refreshAfterAddingData = true) { SetCommonChartProperties(chartTitle, chartSubtitle); if (!data.Any()) { return; } double min = data.Min(p => p.X); double max = data.Max(p => p.X); double binWidth = (max - min) / numBins; var histogramSeries = new RectangleBarSeries(); double binFloor = min; for (int i = 0; i < numBins; i++) { var binData = data.Where(p => p.X >= binFloor && p.X < binFloor + binWidth); var bin = new RectangleBarItem(binFloor, 0, binFloor + binWidth, binData.Count()); histogramSeries.Items.Add(bin); binFloor += binWidth; } histogramSeries.StrokeThickness = borderThickness; if (fillColor.HasValue) { histogramSeries.FillColor = fillColor.Value; } if (borderColor.HasValue) { histogramSeries.StrokeColor = borderColor.Value; } var xAxis = new LinearAxis() { MajorStep = binWidth, Position = AxisPosition.Bottom, StringFormat = "F2", MinorTickSize = 0, Title = xAxisLabel }; var yAxis = new LinearAxis() { Position = AxisPosition.Left, MinorTickSize = 0, Title = "Count" }; if (!Model.Axes.Any()) { Model.Axes.Add(xAxis); Model.Axes.Add(yAxis); } Model.Series.Add(histogramSeries); if (refreshAfterAddingData) { RefreshChart(); } }
private void CreateBarSeries(LinearAxis linearAxis2, PlotModel plotModel) { var barSeries = new RectangleBarSeries {StrokeThickness = 0}; var dif = GetDiff(Data.Grouping); foreach (var p in Data.GetGroupedDataSet()[0]) { var r = new RectangleBarItem(p.Key, 0, p.Key + dif, p.Value, color: OxyColors.Blue); barSeries.Items.Add(r); } plotModel.Series.Add(barSeries); }
public static PlotModel RectangleBarSeriesRenderedOnTopLayer() { var plotModel1 = new PlotModel { Title = "RectangleBarSeries rendered on top layer", }; var lineSeries1 = new LineSeries(); lineSeries1.Points.Add(new DataPoint(0, 1)); lineSeries1.Points.Add(new DataPoint(1, 0)); plotModel1.Series.Add(lineSeries1); var rectangleBarSeries1 = new RectangleBarSeries(); rectangleBarSeries1.Items.Add(new RectangleBarItem(0.25, 0.25, 0.75, 0.75)); plotModel1.Series.Add(rectangleBarSeries1); var lineSeries2 = new LineSeries(); lineSeries2.Points.Add(new DataPoint(0, 0)); lineSeries2.Points.Add(new DataPoint(1, 1)); plotModel1.Series.Add(lineSeries2); return plotModel1; }
//bool showXAxis = true, showYAxix = true, isZoomable = true, isMovable = true; //IPlotType chart; //public bool ShowXAxis //{ // get => showXAxis; // set // { // if (showXAxis == value) return; // showXAxis = value; // } //} //public bool ShowYAxix //{ // get => showYAxix; // set // { // if (showYAxix == value) return; // showYAxix = value; // } //} //public bool IsZoomable //{ // get => isZoomable; // set // { // if (isZoomable == value) return; // isZoomable = value; // } //} //public bool IsMovable //{ // get => isMovable; // set // { // if (isMovable == value) return; // isMovable = value; // } //} public async Task Add(PlotModel plotModel) { this.oxyplotModel = new OxyPlot.PlotModel(); this.oxyplotModel.Title = plotModel.Title; foreach (var chart in plotModel.Series) { if (chart is TwoColorArea) //it should be placed before Area if clause { var twoColorAreaSeries = new TwoColorAreaSeries { Color = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color), Color2 = ChartColor.CastToOxyColor(((TwoColorArea)chart).Color2), Limit = ((TwoColorArea)chart).Limit }; foreach (var item in ((TwoColorArea)chart).Data) { twoColorAreaSeries.Points.Add(item); } this.oxyplotModel.Series.Add(twoColorAreaSeries); } else if (chart is Area) { var areaSeries = new AreaSeries(); foreach (var point in ((Area)chart).Data) { areaSeries.Points.Add(point); } this.oxyplotModel.Series.Add(areaSeries); } else if (chart is TwoColorLine)//it should be placed before line if clause { var twoColorLineSeries = new TwoColorLineSeries { Color = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color), Color2 = ChartColor.CastToOxyColor(((TwoColorLine)chart).Color2), Limit = ((TwoColorLine)chart).Limit }; foreach (var item in ((TwoColorLine)chart).Data) { twoColorLineSeries.Points.Add(item); } this.oxyplotModel.Series.Add(twoColorLineSeries); } else if (chart is Line) { var lineSeries = new LineSeries { MarkerType = MarkerType.Circle, MarkerSize = 4, MarkerStroke = OxyColors.White }; foreach (var point in ((Line)chart).Data) { lineSeries.Points.Add(point); } this.oxyplotModel.Series.Add(lineSeries); } else if (chart is Pie) { var pieSeries = new PieSeries(); foreach (var slice in ((Pie)chart).Data) { pieSeries.Slices.Add(slice); } this.oxyplotModel.Series.Add(pieSeries); } else if (chart is Bar) { var barSeries = new BarSeries(); foreach (var item in ((Bar)chart).Data) { barSeries.Items.Add(item); } this.oxyplotModel.Series.Add(barSeries); } else if (chart is ErrorColumn) { var errorColumn = new ErrorColumnSeries(); foreach (ErrorColumnItem item in ((ErrorColumn)chart).Data) { errorColumn.Items.Add((OxyPlot.Series.ErrorColumnItem)item); } this.oxyplotModel.Series.Add(errorColumn); } else if (chart is Column) { var barSeries = new ColumnSeries(); foreach (var item in ((Column)chart).Data) { barSeries.Items.Add(item); } this.oxyplotModel.Series.Add(barSeries); } else if (chart is Box) { var boxSeries = new BoxPlotSeries(); foreach (var item in ((Box)chart).Data) { boxSeries.Items.Add(item); } this.oxyplotModel.Series.Add(boxSeries); } else if (chart is Contour) { var contourSeries = new ContourSeries { Data = ((Contour)chart).Data, ColumnCoordinates = ((Contour)chart).ColumnCoordinates, RowCoordinates = ((Contour)chart).RowCoordinates }; this.oxyplotModel.Series.Add(contourSeries); } else if (chart is RectangleBar) { var rectangleBarSeries = new RectangleBarSeries { Title = ((RectangleBar)chart).Title }; foreach (var item in ((RectangleBar)chart).Data) { rectangleBarSeries.Items.Add(item); } this.oxyplotModel.Series.Add(rectangleBarSeries); } else if (chart is CandleStick) { var candleStickSeries = new CandleStickSeries(); foreach (var item in ((CandleStick)chart).Data) { candleStickSeries.Items.Add(item); } this.oxyplotModel.Series.Add(candleStickSeries); } else if (chart is HeatMap) { var heatMapSeries = new HeatMapSeries() { Data = ((HeatMap)chart).Data, X0 = ((HeatMap)chart).X0, X1 = ((HeatMap)chart).X1, Y0 = ((HeatMap)chart).Y0, Y1 = ((HeatMap)chart).Y1, Interpolate = ((HeatMap)chart).Interpolate, RenderMethod = ((HeatMap)chart).RenderMethod }; this.oxyplotModel.Series.Add(heatMapSeries); } else if (chart is HighLow) { var highLowSeries = new HighLowSeries(); foreach (var item in ((HighLow)chart).Data) { highLowSeries.Items.Add(item); } this.oxyplotModel.Series.Add(highLowSeries); } else if (chart is IntervalBar) { var intervalBarSeries = new IntervalBarSeries(); foreach (var item in ((IntervalBar)chart).Data) { intervalBarSeries.Items.Add(item); } this.oxyplotModel.Series.Add(intervalBarSeries); } else if (chart is Scatter) { var scatterSeries = new ScatterSeries(); foreach (var item in ((Scatter)chart).Data) { scatterSeries.Points.Add(item); } this.oxyplotModel.Series.Add(scatterSeries); } } foreach (var axis in plotModel.Axes) { this.oxyplotModel.Axes.Add(axis); } }