question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalPlot fails when arrays contain double.NaN

See original GitHub issue

Describe the bug When I create a second SignalPlot using a List, it is only shown after zoom in. I guess I only miss something basic…?

To Reproduce Create a SignalPlot with rand numbers, then a List based on this array, and send it to a second SignalPlot.

// include code to help us reproduce this bug
using MathNet.Numerics.Statistics;
using ScottPlot;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScottPlot_PlotSignalNotShown
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Random rand = new Random(0);
            int pointCount = (int)1e5;
            double[] array1 = DataGen.RandomWalk(rand, pointCount);
            
            formsPlot1.plt.PlotSignal(array1, 1, 0, 0, color: Color.Blue, 2, 6, "Signal 1");
            
            List<double> smooth = new List<double>();
            MovingStatistics moving_aver = new MovingStatistics(24);
            foreach (double value in array1)
            {
                moving_aver.Push(value);
                smooth.Add(Math.Round(moving_aver.Variance));
            }

            formsPlot1.plt.PlotSignal(smooth.ToArray(), 1, 0, 0, color: Color.Green, 2, 6, "Signal 1 variance");

            formsPlot1.plt.Legend(true, fontSize: 18, location: legendLocation.upperRight);
            formsPlot1.Render();
        }
    }
}

Screenshots image

After zoom in:

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Teravuscommented, Oct 18, 2021

This feature helps a LOT. I’m so happy that you added this validation method. I checked everything for NaN prior to adding the arrays to the Plot, but… it turns out the SignalXYConst is unable to deal with values where (i+1 <= i) on the X axis, and, as a result, the graph was crashing intermittently when drag/scrolling with a NaN error message.

Calling this method helped fix that X+1 <= X on the X axis. image

2reactions
StendProgcommented, Sep 17, 2020

After some thought, I found that it would be handy. When the user is faced with an incomprehensible problem, give him the opportunity to turn on the diagnostic mode in one place at init. Something like:

plt.EnableDiagnostic ().

As a result, all data would be checked on every Render, and throw exceptions describing the problem. Performance is irrelevant in diagnostic mode. I still vaguely imagine how this can be done through decorators, so that it absolutely does not affect the standard mode, but I will see what can be done. In the future, this mode can be expanded with additional checks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalPlot fails when arrays contain double.NaN · Issue #546
Describe the bug When I create a second SignalPlot using a List, it is only shown after zoom in. I guess I only...
Read more >
ScottPlot, NaN, and Infinity
In general it is a good idea to avoid plotting data containing any of: Most plot types cannot display double[] containing: Double.PositiveInfinity; Double....
Read more >
c# - Sorting an array of Doubles with NaN in it
I came across a problem at work where we were using NaN values in a table, but when the table was sorted, it...
Read more >
Simple Method for Finding if ANY NaN values occur in a ...
Is there a quick method of finding out whether or not a matrix or a vector in matlab has any NaN values? A...
Read more >
API — asammdf "7.3.14" documentation
returns Signal if samples_only*=*False (default option), otherwise returns a (numpy.array, None) tuple (for compatibility with MDF v4 class. The Signal samples ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found