-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Labels
BUGunexpected behaviorunexpected behavior
Description
@painstgithub noted in #1748 that automatic axis limits do not properly account for negative offsets
double[] heights = ScottPlot.DataGen.Ones(21);
double[] bases = ScottPlot.DataGen.Sin(21);
var bar = formsPlot1.Plot.AddBar(heights);
bar.ValueOffsets = bases;That logic is here:
ScottPlot/src/ScottPlot4/ScottPlot/Plottable/BarPlotBase.cs
Lines 108 to 138 in b73692f
| public virtual AxisLimits GetAxisLimits() | |
| { | |
| double valueMin = double.PositiveInfinity; | |
| double valueMax = double.NegativeInfinity; | |
| double positionMin = double.PositiveInfinity; | |
| double positionMax = double.NegativeInfinity; | |
| for (int i = 0; i < Positions.Length; i++) | |
| { | |
| valueMin = Math.Min(valueMin, Values[i] - ValueErrors[i] + ValueOffsets[i]); | |
| valueMax = Math.Max(valueMax, Values[i] + ValueErrors[i] + ValueOffsets[i]); | |
| positionMin = Math.Min(positionMin, Positions[i]); | |
| positionMax = Math.Max(positionMax, Positions[i]); | |
| } | |
| valueMin = Math.Min(valueMin, ValueBase); | |
| valueMax = Math.Max(valueMax, ValueBase); | |
| if (ShowValuesAboveBars) | |
| valueMax += (valueMax - valueMin) * .1; // increase by 10% to accommodate label | |
| positionMin -= BarWidth / 2; | |
| positionMax += BarWidth / 2; | |
| positionMin += PositionOffset; | |
| positionMax += PositionOffset; | |
| return Orientation == Orientation.Vertical ? | |
| new AxisLimits(positionMin, positionMax, valueMin, valueMax) : | |
| new AxisLimits(valueMin, valueMax, positionMin, positionMax); | |
| } |
I think the error is here:
ScottPlot/src/ScottPlot4/ScottPlot/Plottable/BarPlotBase.cs
Lines 117 to 118 in b73692f
| valueMin = Math.Min(valueMin, Values[i] - ValueErrors[i] + ValueOffsets[i]); | |
| valueMax = Math.Max(valueMax, Values[i] + ValueErrors[i] + ValueOffsets[i]); |
valueMin should represent the base of each bar and not include the Values[i] unless it is negative
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BUGunexpected behaviorunexpected behavior
