public void Test_Bar_ErrorLineWidth() { var plt = new ScottPlot.Plot(); // start with default settings double[] ys = new double[] { 1, 3, 2, 4 }; var bar = new BarPlot(null, ys, ys, null) { }; plt.Add(bar); var bmp1 = TestTools.GetLowQualityBitmap(plt); // change the plottable bar.ErrorLineWidth += 1; var bmp2 = TestTools.GetLowQualityBitmap(plt); // measure what changed //TestTools.SaveFig(bmp1, "1"); //TestTools.SaveFig(bmp2, "2"); var before = new MeanPixel(bmp1); var after = new MeanPixel(bmp2); Console.WriteLine($"Before: {before}"); Console.WriteLine($"After: {after}"); Assert.That(after.IsDarkerThan(before)); }
public static List <BarPlot> HistogramPlot(VisFileContainer v) { List <BarPlot> ret = new List <BarPlot>(); BarPlot histogram = MakeBarPlot(v.valueTable["latency_values"], v.valueTable["latency_counts"], Color.SlateGray); ret.Add(histogram); return(ret); }
/// <summary> /// Create a series of bar plots and customize the ticks and legend /// </summary> public BarPlot[] AddBarGroups(string[] groupLabels, string[] seriesLabels, double[][] ys, double[][] yErr) { if (groupLabels is null || seriesLabels is null || ys is null) { throw new ArgumentException("labels and ys cannot be null"); } if (seriesLabels.Length != ys.Length) { throw new ArgumentException("groupLabels and ys must be the same length"); } foreach (double[] subArray in ys) { if (subArray.Length != groupLabels.Length) { throw new ArgumentException("all arrays inside ys must be the same length as groupLabels"); } } double groupWidthFraction = 0.8; double barWidthFraction = 0.8; double errorCapSize = 0.38; int seriesCount = ys.Length; double barWidth = groupWidthFraction / seriesCount; BarPlot[] bars = new BarPlot[seriesCount]; bool containsNegativeY = false; for (int i = 0; i < seriesCount; i++) { double[] barYs = ys[i]; double[] barYerr = yErr?[i]; double[] barXs = DataGen.Consecutive(barYs.Length); containsNegativeY |= barYs.Where(y => y < 0).Any(); var bar = new BarPlot(barXs, barYs, barYerr, null) { Label = seriesLabels[i], BarWidth = barWidth * barWidthFraction, XOffset = i * barWidth, ErrorCapSize = errorCapSize, FillColor = GetNextColor() }; bars[i] = bar; Add(bar); } if (containsNegativeY) { AxisAuto(); } double[] groupPositions = DataGen.Consecutive(groupLabels.Length, offset: (groupWidthFraction - barWidth) / 2); XTicks(groupPositions, groupLabels); return(bars); }
/// <summary> /// Add a bar plot (values +/- errors) using defined positions /// </summary> public BarPlot AddBar(double[] values, double[] errors, double[] positions, Color?color = null) { var plottable = new BarPlot(positions, values, errors, null) { FillColor = color ?? GetNextColor() }; Add(plottable); return(plottable); }
/// <summary> /// Add a bar plot for the given values. Bars will be placed at X positions 0, 1, 2, etc. /// </summary> public BarPlot AddBar(double[] values, Color?color = null) { double[] xs = DataGen.Consecutive(values.Length); var plottable = new BarPlot(xs, values, null, null) { FillColor = color ?? GetNextColor() }; Add(plottable); return(plottable); }
public static List <BarPlot> PowerGraph(VisFileContainer v) { p("PowerGraph for " + v.filepath); List <BarPlot> plots = new List <BarPlot>(); Dictionary <string, List <decimal> > valueTable = v.valueTable; int numValues = valueTable["x_axis"].Count; ComputeStackedBarValues(v, 0, Grapher.ZeroList(numValues)); Color c; // run the loop from 1 since the 0th case is taken care of above for (uint r = 1; r <= v.systemParameters.NUM_RANKS; r++) { //when r==NUM_RANKS, we don't want to compute the stacked values if (r < v.systemParameters.NUM_RANKS) { ComputeStackedBarValues(v, (int)r, valueTable["refresh_top_" + (r - 1)]); } uint x = (r - 1) * 2; //adding these in reverse order of the stacks makes the legend work out well c = Grapher.GetColorRange(x, 0, 3); BarPlot bp = MakeBarPlot(valueTable["x_axis"], valueTable["refresh_top_" + (r - 1)], valueTable["burst_top_" + (r - 1)], c); bp.Label = "Refresh (Rank " + r + ")"; plots.Add(bp); c = Grapher.GetColorRange(x, 2, 3); bp = MakeBarPlot(valueTable["x_axis"], valueTable["burst_top_" + (r - 1)], valueTable["actpre_top_" + (r - 1)], c); bp.Label = "Burst (Rank " + r + ")"; plots.Add(bp); c = Grapher.GetColorRange(x, 1, 3); bp = MakeBarPlot(valueTable["x_axis"], valueTable["actpre_top_" + (r - 1)], valueTable["background_top_" + (r - 1)], c); bp.Label = "Activate/Precharge (Rank " + r + ")"; plots.Add(bp); c = Grapher.GetColorRange(x, 3, 3); bp = MakeBarPlot(valueTable["x_axis"], valueTable["background_top_" + (r - 1)], valueTable["background_bottom_" + (r - 1)], c); bp.Label = "Background Power (Rank " + r + ")"; plots.Add(bp); } /* * * * // plot.Legend.NeverShiftAxes=true; * */ // computeBarGraphTimeScales(); // SetBarGraphWidths(plot); return(plots); }
//make a bar graph with an arbitrary bottom value public static BarPlot MakeBarPlot(List <decimal> xAxis, List <decimal> barTops, List <decimal> barBottoms, Color color) { BarPlot h = new BarPlot(); h.AbscissaData = xAxis; h.OrdinateDataTop = barTops; h.OrdinateDataBottom = barBottoms; h.BarWidth = 3; h.BorderColor = color; h.FillBrush = new NPlot.RectangleBrushes.Solid(color); return(h); }
public void SetBarGraphWidths(NPlot.Windows.PlotSurface2D canvas) { double numBars = (canvas.XAxis1.WorldLength) / (double)this.timeScale[canvas]; foreach (IDrawable drawable in canvas.Drawables) { if (drawable is BarPlot) { BarPlot bp = (BarPlot)drawable; bp.BarWidth = (float)Math.Floor(canvas.Width / (numBars)) - 4.0f; if (bp.BarWidth < 0) { bp.BarWidth = 1.0f; } } } canvas.Refresh(); }
/// <summary> /// This method creates a figure for a bar plot. /// </summary> /// <remarks>A figure environment will be placed somewhere according to position settings. /// It is an floating environment.</remarks> /// <param name="caption">Text for figure caption.</param> /// <param name="plot">Plot settings needed for generation.</param> /// <param name="converter">TEX converter.</param> internal static string BarPlotFigure(string caption, BarPlot plot, ITeXConverter converter) { var isLegendBeside = plot.AxisOptions.LegendOptions != null && getIsLegendBeside(plot.AxisOptions.LegendOptions.LegendPosition); adjustAxisDimensionForFigures(plot.AxisOptions, plot.Landscape, isLegendBeside, 90, 60); var maxLegendEntry = getMaxLegendEntryLength(plot.Plots); if (plot.AxisOptions.LegendOptions != null) { if (String.IsNullOrEmpty(plot.AxisOptions.LegendOptions.TextWidth)) { plot.AxisOptions.LegendOptions.TextWidth = getLegendWidth(plot.AxisOptions.LegendOptions.LegendPosition, plot.Landscape, maxLegendEntry); } } var pictureText = new PlotWriter(plot.Colors, converter).Picture(plot.BarPlotOptions, plot.AxisOptions, plot.Plots); return(plotFigure(caption, plot, pictureText)); }
public override void Build(Histogram histogram, OSPSuiteTracker buildTracker) { var distributionData = _distributionDataCreator.CreateFor(histogram.ParameterContainer, histogram.ParameterDistributionSettings); var colors = new List <Color>() { PKSimColors.Male, PKSimColors.Female }; var settings = histogram.ParameterDistributionSettings.Settings; var axisOptions = getAxisOptions(settings, distributionData); var barPlotOptions = getBarPlotOptions(settings, distributionData); var plots = getPlots(distributionData); var caption = new Text("{0} of {1}", PKSimConstants.UI.Distribution, settings.PlotCaption ?? string.Empty); var histogramPlot = new BarPlot(colors, axisOptions, barPlotOptions, plots, caption) { Position = FigureWriter.FigurePositions.H }; _builderRepository.Report(histogramPlot, buildTracker); }
public static void TestEmptyDataCharts() { // the PlotView is a WPF control that's created in the .xaml code OxyPlot.Wpf.PlotView examplePlotView = new OxyPlot.Wpf.PlotView(); List <Datum> data = new List <Datum>(); Plot plot = new ScatterPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new LinePlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new BarPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new HistogramPlot(examplePlotView, data, 10); Assert.That(plot.Model.Series.Count == 0); plot = new SpectrumPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); }
public BarPlot PlotBar( double[] xs, double[] ys, double[] errorY = null, string label = null, double barWidth = .8, double xOffset = 0, bool fill = true, Color?fillColor = null, double outlineWidth = 1, Color?outlineColor = null, double errorLineWidth = 1, double errorCapSize = .38, Color?errorColor = null, bool horizontal = false, bool showValues = false, Color?valueColor = null, bool autoAxis = true, double[] yOffsets = null, Color?negativeColor = null ) { Color nextColor = settings.GetNextColor(); BarPlot barPlot = new BarPlot(xs, ys, errorY, yOffsets) { BarWidth = barWidth, XOffset = xOffset, FillColor = fillColor ?? nextColor, Label = label, ErrorLineWidth = (float)errorLineWidth, ErrorCapSize = errorCapSize, ErrorColor = errorColor ?? Color.Black, BorderLineWidth = (float)outlineWidth, BorderColor = outlineColor ?? Color.Black, VerticalOrientation = !horizontal, ShowValuesAboveBars = showValues, FillColorNegative = negativeColor ?? nextColor }; barPlot.Font.Color = valueColor ?? Color.Black; Add(barPlot); if (autoAxis) { // perform a tight axis adjustment AxisAuto(0, 0); var tightAxisLimits = GetAxisLimits(); // now loosen it up a bit AxisAuto(); // now set one of the axis edges to zero if (horizontal) { if (tightAxisLimits.XMin == 0) { SetAxisLimits(xMin: 0); } else if (tightAxisLimits.XMax == 0) { SetAxisLimits(xMax: 0); } } else { if (tightAxisLimits.YMin == 0) { SetAxisLimits(yMin: 0); } else if (tightAxisLimits.YMax == 0) { SetAxisLimits(yMax: 0); } } } return(barPlot); }
public PlotMockup() { infoText = ""; infoText += "THE TEST (can your charting library handle this?) - \n"; infoText += "NPlot demonstrates it can handle real world charting requirements."; // first of all, generate some mockup data. DataTable info = new DataTable("Store Information"); info.Columns.Add("Index", typeof(int)); info.Columns.Add("IndexOffsetLeft", typeof(float)); info.Columns.Add("IndexOffsetRight", typeof(float)); info.Columns.Add("StoreName", typeof(string)); info.Columns.Add("BarBase", typeof(float)); info.Columns.Add("StoreGrowth", typeof(float)); info.Columns.Add("AverageGrowth", typeof(float)); info.Columns.Add("ProjectedSales", typeof(float)); float barBase = 185.0f; Random r = new Random(); for (int i = 0; i < 18; ++i) { DataRow row = info.NewRow(); row["Index"] = i; row["IndexOffsetLeft"] = (float)i - 0.1f; row["IndexOffsetRight"] = (float)i + 0.1f; row["StoreName"] = "Store " + (i + 1).ToString(); row["BarBase"] = barBase; row["StoreGrowth"] = barBase + ((r.NextDouble() - 0.1) * 20.0f); row["AverageGrowth"] = barBase + ((r.NextDouble() - 0.1) * 15.0f); row["ProjectedSales"] = barBase + (r.NextDouble() * 15.0f); info.Rows.Add(row); barBase += (float)r.NextDouble() * 4.0f; } plotSurface.Clear(); plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // generate the grid Grid grid = new Grid(); grid.VerticalGridType = Grid.GridType.Coarse; grid.HorizontalGridType = Grid.GridType.None; grid.MajorGridPen = new Pen(Color.Black, 1.0f); plotSurface.Add(grid); // generate the trendline LinePlot trendline = new LinePlot(); trendline.DataSource = info; trendline.AbscissaData = "Index"; trendline.OrdinateData = "BarBase"; trendline.Pen = new Pen(Color.Black, 3.0f); trendline.Label = "Trendline"; plotSurface.Add(trendline); // draw store growth bars BarPlot storeGrowth = new BarPlot(); storeGrowth.DataSource = info; storeGrowth.AbscissaData = "IndexOffsetLeft"; storeGrowth.OrdinateDataTop = "StoreGrowth"; storeGrowth.OrdinateDataBottom = "BarBase"; storeGrowth.Label = "Store Growth"; storeGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Black; //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(storeGrowth); // draw average growth bars BarPlot averageGrowth = new BarPlot(); averageGrowth.DataSource = info; averageGrowth.AbscissaData = "IndexOffsetRight"; averageGrowth.OrdinateDataBottom = "BarBase"; averageGrowth.OrdinateDataTop = "AverageGrowth"; averageGrowth.Label = "Average Growth"; averageGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Gray; //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(averageGrowth); // generate the projected sales step line. StepPlot projected = new StepPlot(); projected.DataSource = info; projected.AbscissaData = "Index"; projected.OrdinateData = "ProjectedSales"; projected.Pen = new Pen(Color.Orange, 3.0f); projected.HideVerticalSegments = true; projected.Center = true; projected.Label = "Projected Sales"; projected.WidthScale = 0.7f; plotSurface.Add(projected); // generate the minimum target line. HorizontalLine minimumTargetLine = new HorizontalLine(218, new Pen(Color.Green, 3.5f)); minimumTargetLine.Label = "Minimum Target"; minimumTargetLine.LengthScale = 0.98f; minimumTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(minimumTargetLine); // generate the preferred target line. HorizontalLine preferredTargetLine = new HorizontalLine(228, new Pen(Color.Blue, 3.5f)); preferredTargetLine.Label = "Preferred Target"; preferredTargetLine.LengthScale = 0.98f; preferredTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(preferredTargetLine); // make some modifications so that chart matches requirements. // y axis. plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.YAxis1.TickTextNextToAxis = false; //plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed ((LinearAxis)plotSurface.YAxis1).LargeTickStep = 10.0; ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0; // x axis plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.XAxis1.TickTextNextToAxis = false; //plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < info.Rows.Count; ++i) { la.AddLabel((string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"])); } la.TicksLabelAngle = (float)90.0f; la.TicksBetweenText = true; plotSurface.XAxis1 = la; plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone(); plotSurface.XAxis2.HideTickText = true; plotSurface.XAxis2.LargeTickSize = 0; Legend l = new Legend(); l.NumberItemsVertically = 2; l.AttachTo(XAxisPosition.Bottom, YAxisPosition.Left); l.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside; l.VerticalEdgePlacement = NPlot.Legend.Placement.Inside; l.XOffset = 5; l.YOffset = 50; l.BorderStyle = NPlot.LegendBase.BorderType.Line; plotSurface.Legend = l; plotSurface.Title = "Sales Growth Compared to\n" + "Average Sales Growth by Store Size - Rank Order Low to High"; plotSurface.Refresh(); }
public BarPlot PlotBar( double[] xs, double[] ys, double[] errorY = null, string label = null, double barWidth = .8, double xOffset = 0, bool fill = true, Color?fillColor = null, double outlineWidth = 1, Color?outlineColor = null, double errorLineWidth = 1, double errorCapSize = .38, Color?errorColor = null, bool horizontal = false, bool showValues = false, Color?valueColor = null, bool autoAxis = true, double[] yOffsets = null, Color?negativeColor = null ) { BarPlot barPlot = new BarPlot(xs, ys, errorY, yOffsets) { barWidth = barWidth, xOffset = xOffset, fill = fill, fillColor = fillColor ?? settings.GetNextColor(), label = label, errorLineWidth = (float)errorLineWidth, errorCapSize = errorCapSize, errorColor = errorColor ?? Color.Black, borderLineWidth = (float)outlineWidth, borderColor = outlineColor ?? Color.Black, verticalBars = !horizontal, showValues = showValues, FontColor = valueColor ?? Color.Black, negativeColor = negativeColor ?? Color.Black }; Add(barPlot); if (autoAxis) { // perform a tight axis adjustment AxisAuto(0, 0); var tightAxisLimits = AxisLimits(); // now loosen it up a bit AxisAuto(); // now set one of the axis edges to zero if (horizontal) { if (tightAxisLimits.XMin == 0) { Axis(x1: 0); } else if (tightAxisLimits.XMax == 0) { Axis(x2: 0); } } else { if (tightAxisLimits.YMin == 0) { Axis(y1: 0); } else if (tightAxisLimits.YMax == 0) { Axis(y2: 0); } } } return(barPlot); }