Skip to content

FunctionPlot: RangeX is not respected (likely because min/max are flipped) #3595

@Matthew-Chidlow

Description

@Matthew-Chidlow

If I pass an IFunctionSource into plot.Add.Function() which has specified RangeX to limit the function to the range, then this is ignored and the function will plot over the whole visible range.

I'm pretty sure its because the Min/Max are backwards here:

private double MinX => Math.Min(Source.RangeX.Min.FiniteCoallesce(Axes.XAxis.Min), Axes.XAxis.Min);
private double MaxX => Math.Max(Source.RangeX.Max.FiniteCoallesce(Axes.XAxis.Max), Axes.XAxis.Max);

I believe MinX should be the Max(...) of the two mins, and MaxX should be the Min(...) of the two maxs, from what I understand.

ScottPlot.Plot myPlot = new();
myPlot.Axes.SetLimits(-10, 10, -10, 10);
myPlot.Add.Function(new FunctionSource(x => x)
{
    RangeX = new CoordinateRange(-1.0, 1.0)
});
myPlot.SavePng("bug.png", 300, 300);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueThis issue has limited complexity and may be a good start for new contributorsHelp WantedScott won't do this soon, but PRs from the community are welcome!⚠️ HIGH PRIORITY

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions