How to update a signal plot with a new data array
See original GitHub issueHi
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();
}
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
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:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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