Skip to content

DataLogger: improve axis management for inverted axes #4513

@Jofstera

Description

@Jofstera

Hi guys, is it possible to set a limit on the Y-axis when using a Datalogger?
I know I can set a rule to lock the Y-axis and manually give it tick values, but doing so means the y-axis cannot be expanded dynamically.

ScottPlot Version: WPF SP5 v5.0.45

Code Sample:

    public partial class MainWindow : Window
    {
        readonly System.Windows.Forms.Timer AddNewDataTimer = new() { Interval = 50, Enabled = true };
        ScottPlot.Plottables.DataLogger Logger1;

        public MainWindow()
        {
            InitializeComponent();
            InitializeGraph();
        }

        private void InitializeGraph()
        {
            myPlot.Plot.Axes.InvertY();

            Logger1 = myPlot.Plot.Add.DataLogger();
            Logger1.Axes.YAxis = myPlot.Plot.Axes.Left;

            // Attempting to set some kind of limit ...
            myPlot.Plot.Axes.MarginsY(0);
            myPlot.Plot.Axes.SetLimitsY(0, 50);
            Logger1.Axes.YAxis.Range.Set(0, 50);

            DateTime startOfGraphTime = DateTime.Now;
            Random numGenerator = new Random();
            AddNewDataTimer.Tick += (s, e) =>
            {
                // Attemping to set some kind of limit ...
                myPlot.Plot.Axes.Left.Min = 0;
                Logger1.Axes.YAxis.Min = 0;       
                
                TimeSpan timeSinceStart = DateTime.Now - startOfGraphTime;
                double seconds = timeSinceStart.TotalSeconds;
                Logger1.Add(seconds, numGenerator.Next(0, 50));
                myPlot.Refresh();
            };
        }
    }

image

  1. In this example it is impossible to get a value under 0 or over 50, yet the y-axis shows values outside of this range which are not needed.

  2. I inverted the y-axis with myPlot.Plot.Axes.InvertY();. But as soon as a DataLogger is added to the plot, the Y-axis becomes uninverted. Is there a way to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions