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.

How to update a signal plot with a new data array

See original GitHub issue

Hi

In fact, I use below method to achieve growing data display.

// initial
ScottPlot.PlottableSignal my_plt;
System.Random my_rand = new Random();
List<double> data_growing = new List<double>();
private void formsPlot1_Load(object sender, EventArgs e)
{
    this.data_growing = ScottPlot.DataGen.Random(my_rand, 10).ToList();
    this.my_plt = this.formsPlot1.plt.PlotSignal(data_growing.ToArray());
    this.formsPlot1.Render();
}

// growing
private void button1_Click(object sender, EventArgs e)
{
    data_growing.AddRange(ScottPlot.DataGen.Random(my_rand, 5).ToList());
    this.my_plt.ys = this.data_growing.ToArray();
    this.my_plt.maxRenderIndex = this.my_plt.ys.Length - 1;
    this.formsPlot1.plt.AxisAuto();
    this.formsPlot1.Render();
}

21

But I encountered a problem when I updated from 4.0.39 to 4.0.40. It will report the error IndexOutOfRangeException.

Because the data array my_plt.ys is not synchronized with the array my_plt.minmaxSearchStrategy.SourceArray

Here’s an example of what I’d like to do: Maybe can modify the PlottableSignalBase.updateData program like this image

public void updateData(T[] newData)
{
    //updateData(0, newData.Length, newData);
    this.ys = newData;
    this.maxRenderIndex = this.ys.Length - 1;
    this.minmaxSearchStrategy.SourceArray = newData;
}

Then I can update ys and SourceArray by updateData function at the same time.

private void button1_Click(object sender, EventArgs e)
{
    data_growing.AddRange(ScottPlot.DataGen.Random(my_rand, 5).ToList());
    //this.my_plt.ys = this.data_growing.ToArray();
    //this.my_plt.maxRenderIndex = this.my_plt.ys.Length - 1;
    this.my_plt.updateData(this.data_growing.ToArray()); // Replace the old method
    this.formsPlot1.plt.AxisAuto();
    this.formsPlot1.Render();
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
HowardWhilecommented, Sep 22, 2020

Hi @swharden @StendProg

Thanks for your suggestions. I will follow Solution 2 and make some adjustments to my program to adapt to the new version.

I look forward to the next version and glad to see the outcome.

0reactions
swhardencommented, Sep 26, 2020

@HowardWhile I’m glad we arrived at a solution that works for you!

Good discussion remains about how to improve plottable properties (capitalizing them, making them read-only, etc.), but that’s outside the scope of this issue so I’ll go ahead and close it

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update a signal plot with a new data array #557
A better solution, like @StendProg suggested, is to create a large array one time, then fill its values as you get new data...
Read more >
Plot Live, Changing Data - ScottPlot FAQ
Manually Updating Data in Live Plots. To achieve full control over changing datasets users can use a scatter or signal plot and change...
Read more >
Automatically Refresh Plot After Changing Data - MATLAB ...
Then, call the refreshdata function to update the data properties indirectly. You can use this technique to create animations. Update Plot Using Data...
Read more >
Periodically updating a graph from a continually updating array
The data in the chart display needs to be transposed in order for it to display as you are expecting. Right click on...
Read more >
The Signal class — HyperSpy 1.7.5 documentation
The idea is essentially to specify a subset of the data based on its position in the array and it is therefore essential...
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