QCustomPlot Discussion and Comments

Help with incremental plotting..Return to overview

Hi..I am implementing real time plotting of huge data sets..I have data coming at 100 samples per second from many sensors say around 150 sensors..So i have to use multiple custom plot widgets..I have to do real time plotting for around 1.5 hrs to 2 hrs.My doubt is whether is it possible to do incremental kind of plotting i.e., adding new points to the existing points on the graph instead of replotting the large set of data..so is there a way to paint the plot incrementally on the plot widget without erasing the old points so that next time when new data points come i can simply append the new points..thank you..

100 Samples per second for 150 sensors for 2 hours are 108,000,000 data points. That's about 5 Gigabytes of data, with the storage overhead probably a bit more. This definitely calls for a specialized plottable that you write specifically for that purpose and which has exactly the features you need with highly optimized CPU and memory usage.
It might also make sense to only show a few sensors at a time...

I've found that for plotting streaming data (where you don't expect to go back and insert data midstream) that a QVector of the QCPData works better and has lower memory usage than a QMap. Since the data is already sorted on the key axis, it's fairly easy to create a replacement of QCPGraph that maintains the same external api yet uses a sorted vector internally. The main changes were in the implementation of getVisibleDataBounds (QVector doesn't have a lowerBound/upperBound implementation, so you have to use QAlgorithm's version and implement a "less than" functor for QCPData) and replace various iterator calls to key() and value() to access key/value directly from QCPData.


If your goal is just to display the data without interactions on the graphs, you can try and plot only a timespan of the data. Add data to the graphs periodically, reset the visible ranges, and remove oldest entries once their keys go out of a specified range, assuming that your keyAxis is time (UTC or ?). You can try and keep each graph under an only thread, and replot everything together, I find it more efficient (the volume of data in memory is minimised) and the CPU is quite at ease with not having to do deal with numerous threads running around.
Although, you can try and limit the number of QCustomplot widgets your application loads :
e.g.: if your graphs all use time as key and raw number as value, you can always modify the default layout and add QCPItemRects and QCPGraphs, pile them up, and link them all together, disable all axis but the bottom of the lowest rectangle which will serve as timescale...