Behavior of AddFill in complex scenarios
See original GitHub issueHi @swharden & Team,
i have played a little with the function:
Polygon AddFill(double[] xs1, double[] ys1, double[] xs2, double[] ys2, Color? color = null)
It looks like the function is not intended for complex scenarios. That is, a variable number of values on the X-axis or Y-axis. The following errors occur if xs1
and xs2
is different:
System.IndexOutOfRangeException: Index was outside the bounds of the array. at ScottPlot.Plot.AddFill(Double[] xs1, Double[] ys1, Double[] xs2, Double[] ys2, Nullable`1 color) at ExchangePlotter.InteractivChart.AddData(ChartInput ci) in d:\Code\ExchangePlotter\InteractivChart.cs:line 78
If the number of xs1
and xs2
is equal but ys1
and ys2
have different amounts, this exception happens:
System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array’s lower bounds. at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at ScottPlot.Plot.AddFill(Double[] xs1, Double[] ys1, Double[] xs2, Double[] ys2, Nullable`1 color) at ExchangePlotter.InteractivChart.AddData(ChartInput ci) in d:\Code\ExchangePlotter\InteractivChart.cs:line 78
This is not urgent. It would be cool if the number of points for X/Y didn’t matter. As long as the areas for xs1
, xs2
overlap, interpolation would certainly be possible to find “missing” points on one or the other line to span the polygon. Is probably very complex to implement? I’ll leave it here in case someone is bored 😉
Version: ScottPlot 4.1.8-beta
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Thank you @bclehmann for the quick feedback and explanation. Than i think we can close the ticket. I know how i can do it! 👍
For 1) It plots between curves by creating a closed polygon out of the two curves. In this situation that polygon intersects itself. The only alternative I can think of is to only create the polygon where the x-value overlap (i.e. ignore the second half of
xs1
andys1
in the example I gave). I don’t particularly like that alternative because in my mind that’s not the behavior I would expect in this situation.For 2),
AddFill
returns aPlottablePolygon
which has aLabel
field that you can edit and can show up in the legend.For 3) I believe you can simply pass in a colour to
AddFill
with whatever degree of opacity you want (i.e. the alpha channel can be set to 0 for full transparency or 255 for full opacity or anywhere in between).