Skip to content

Scatter Plot: ArgumentNullException when YError is set but XError is null #1237

@simmdan

Description

@simmdan

Bug Report

Issue: If I create a scatter plot, set x and y data series and then set the yError information but not xError information (because I only want vertical error bars), I get an ArgumentNullException:

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null. (Parameter 'second')
  Source=System.Linq
  StackTrace:
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Zip[TFirst,TSecond,TResult](IEnumerable`1 first, IEnumerable`1 second, Func`3 resultSelector)
   at ScottPlot.Plottable.ScatterPlot.GetAxisLimits() in C:\dev\ScottPlot\src\ScottPlot\Plottable\ScatterPlot.cs:line 187
   at ScottPlot.Settings.<>c.<AxisAutoX>b__53_4(IPlottable x) in C:\dev\ScottPlot\src\ScottPlot\Settings.cs:line 361
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at ScottPlot.Settings.AxisAutoX(Int32 xAxisIndex, Double margin) in C:\dev\ScottPlot\src\ScottPlot\Settings.cs:line 357
   at ScottPlot.Settings.AxisAutoUnsetAxes() in C:\dev\ScottPlot\src\ScottPlot\Settings.cs:line 268
   at ScottPlot.Plot.Render(Bitmap bmp, Boolean lowQuality, Double scale) in C:\dev\ScottPlot\src\ScottPlot\Plot\Plot.Render.cs:line 29
   at ScottPlot.Plot.Render(Int32 width, Int32 height, Boolean lowQuality, Double scale) in C:\dev\ScottPlot\src\ScottPlot\Plot\Plot.Render.cs:line 165
   at ScottPlot.Plot.Render(Boolean lowQuality) in C:\dev\ScottPlot\src\ScottPlot\Plot\Plot.Render.cs:line 148
   at ScottPlotTests.TestTools.GetLowQualityBitmap(Plot plt) in C:\dev\ScottPlot\src\tests\TestTools.cs:line 12
   at ScottPlotTests.PlottableRenderTests.Scatter.Test_Scatter_ChangeOnlyYErrorData() in C:\dev\ScottPlot\src\tests\PlottableRenderTests\Scatter.cs:line 83

Reproducing:

var plt = new ScottPlot.Plot();

double[] xs = { 1, 2, 3, 4 };
double[] ys = { 1, 4, 9, 16 };
double[] yErr = { .5, .5, 1, 1 };
// set errorY but NOT errorX
var splt = new ScatterPlot(xs, ys, errorY: yErr) { };

System Details

  • ScottPlot Version: 4.1.17, but also on the tip of master cloned from GitHub on 9/2/2021
  • Operating System: Windows 10
  • Application Type: console
  • .NET Version: .NET 5.0

NOTE: I have a PR incoming which adds a simple test and then does the 1 character fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGunexpected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions