QCustomPlot Discussion and Comments

Performance in Realtime plottingReturn to overview

Hi there!

I have a realtime plot with 4 graphs and with a ton of data. The vectors get sent to the plot every ~5 sec.
Currently, I am plotting a total of 20 seconds by removing the oldest 5 sec from the plot with removeBefore.
I tested the code with addData and withsetData, but both result in a total of about 600ms to plot. There is no difference in perfomance whether I use add or set Data which I find surprinsing. renew_plot_data is called every 5 seconds.


renew_plot_data:

    

QElapsedTimer timer;
timer.start();
for(int i=0; i<6; i++)
{        
 if(Active[i])
 {

  actualWidget->graph(i)->setVisible(Active[i]);
  actualWidget->graph(i)->data()->removeBefore(key - (MAX_REPS - 1)* TIME_BASE );
  actualWidget->graph(i)->addData(time, data_plot[InvNum[i]][ParNum[i]]);
  actualWidget->graph(i)->setName(StrNum[i]);
  actualWidget->graph(i)->addToLegend();
 }
}
actualWidget->xAxis->rescale(true);
actualWidget->replot();
qDebug()<< "all in all plot data took " << timer.elapsed() << " ms.";
qDebug() << "end for.";
       


but this results in the same performance (if in both cases only 5sec are shown)


    

QElapsedTimer timer;
timer.start();
for(int i=0; i<6; i++)
{        
 if(Active[i])
 {

  actualWidget->graph(i)->setVisible(Active[i]);
  actualWidget->graph(i)->setData(time, data_plot[InvNum[i]][ParNum[i]]);
  actualWidget->graph(i)->setName(StrNum[i]);
  actualWidget->graph(i)->addToLegend();
 }
}
actualWidget->xAxis->rescale(true);
actualWidget->replot();
qDebug()<< "all in all plot data took " << timer.elapsed() << " ms.";
qDebug() << "end for.";
       

From my understanding, addData should result in a better performance.
I try to reduce the replotting time as during that time the graph cannot be moved neither comboboxes or checkboxes can be clicked, resulting in a feelable lag.


Thank you in advance!
Best

as far as i know, the only difference between addData and setData is that setData has to loop through and set more values. (in your case, 15 extra seconds worth)... but if you dont have a lot of data in that 15 seconds, then the time savings in this case would be negligible.

however, if you had a plot with 1M points and then wanted to add a single point, obviously it would be faster to add 1 point than 1M+1.

The majority of the plotting time is related to calculating the bounds(if you call rescale axes) and the actual drawing time. neither of these are affected by the current implementation of addData or setData.

Thank you Ian!
I made some changes on the order (put some things in front of the for-loop etc) and used the "already sorted" bool of add/set Data and got down to about 25ms/graph. During that time, however, no new data is collected, therefore resulting in a blank space. Thats why I want to minimate the drawing time. It is only max 100ms but still 100ms where no data is collected.
Is it true, that it is not possible to replot the graph outside the GUI thread?

Thank you in advance :)

I also have an app that plots real-time data and if I have line widths anything other than 0, the app runs VERY slow. My advice would be to try that.

For real time plots, you should be doing data acquisition in a separate thread from the gui thread anyway.

whats good bruwww

In an application I work on, we are able to plot hundreds of frames per second to a qcp colormap. The data are similar to uncompressed HD video. We also do profile plots in line plots at these rates. There is not any problem going up to 300 FPS in our application.