Skip to content

IPlotControl: Extension method for simplified axis linking #4003

@swharden

Description

@swharden

Create something like this

public static class ScottPlotExtensions
{
    /// <summary>
    /// Update another plot control's axis limits when this one's change
    /// </summary>
    public static void ShareAxisLimits(this IPlotControl source, IPlotControl target, bool x = true, bool y = true)
    {
        if (source == target)
            throw new ArgumentException("Cannot link a plot control to itself");

        source.Plot.RenderManager.AxisLimitsChanged += (s, e) =>
        {
            AxisLimits sourceLimits = source.Plot.Axes.GetLimits();
            if (x) target.Plot.Axes.SetLimitsX(sourceLimits.Left, sourceLimits.Right);
            if (y) target.Plot.Axes.SetLimitsY(sourceLimits.Bottom, sourceLimits.Top);
            target.Plot.RenderManager.DisableAxisLimitsChangedEventOnNextRender = true;
            target.Refresh();
        };
    }
}

which makes it easy to link plot controls together like this:

formsPlot1.ShareAxisLimits(formsPlot2, x: true, y: false);
formsPlot2.ShareAxisLimits(formsPlot1, x: true, y: false);

Then update the docs to show how to use it

https://scottplot.net/demo/5.0/#shared-axes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions