Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why QCustomPlot is too slow in ploting large data?

I want to plotting some large chunk of data (3k) which is coming every 100ms. I tried QCustomPlot and Qwt with exact 3k points and i got really good performances in plotting with Qwt and really bad performances with QCustomPlot. And i think i behave wrongly with QCustomPlot, i used this code for plotting in QCustomPlot (This example is from QCustomPlot plot-examples which i edited function setupQuadraticDemo):

void  MainWindow::setupQuadraticDemo(QCustomPlot *customPlot)
{
 demoName = "Quadratic Demo";
 customPlot->addGraph();
 customPlot->setNotAntialiasedElements(QCP::AntialiasedElement::aeAll);

 customPlot->xAxis->setRange(0, 1000);
 customPlot->yAxis->setRange(0, 1000);

 customPlot->xAxis->setLabel("x");
 customPlot->yAxis->setLabel("y");

 connect(&dataTimer, &QTimer::timeout, this, [customPlot]
 {
  constexpr auto length = 3000;
  QVector<double> x(length), y(length);

  std::srand(std::time(nullptr));

  for (int i = 0; i < length; ++i)
  {
   x[i] = std::rand() % 1000;
   y[i] = std::rand() % 1000;
  }

  customPlot->graph(0)->setData(x, y, true);

  customPlot->replot();
 });

 dataTimer.start(100);
}

And this code for Qwt. Is i do wrong with QCustomPlot ? Why it's too slow in plotting ?

like image 479
Ghasem Ramezani Avatar asked Dec 06 '25 18:12

Ghasem Ramezani


1 Answers

I guess that the root of the problem is the code itself. You are updating points in the wrong way. You have to delete the below line from your code

std::srand(std::time(nullptr));

This line will force the rand()'s seed to be fixed for a deterministic time(if I want to be precise your seed value is fixed for 1 second), so whether the data itself is updated or not you cannot see any changes because the replot is going to plot the same points for that duration(1 sec).

like image 152
Saeed Masoomi Avatar answered Dec 08 '25 08:12

Saeed Masoomi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!