【问题标题】:Why QCustomPlot is too slow in ploting large data?为什么 QCustomPlot 在绘制大数据时速度太慢?
【发布时间】:2021-02-05 21:01:50
【问题描述】:

我想绘制每 100 毫秒出现的大量数据 (3k)。我尝试了 QCustomPlotQwt 精确的 3k 点,我在使用 Qwt 绘图时获得了非常好的性能,而使用 QCustomPlot 时的性能非常差。而且我认为我对 QCustomPlot 的行为有误,我使用此代码在 QCustomPlot 中绘图(此示例来自 QCustomPlot plot-examples,我编辑了函数 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);
}

还有this code 用于 Qwt。我对 QCustomPlot 做错了吗?为什么绘图速度太慢了?

【问题讨论】:

  • 您不需要在每次重绘时重新分配向量。什么是“太慢”?你测量过重绘需要多长时间吗?
  • 我用 Qwt 做我所做的事情,是的,我测量重绘需要多长时间。

标签: c++ qt gcc qwt qcustomplot


【解决方案1】:

我猜问题的根源在于代码本身。您以错误的方式更新点。您必须从代码中删除以下行

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

这条线将强制rand()的种子在确定的时间内固定(如果我想准确地说你的种子值是为1 second固定的),所以无论数据本身是否更新,你都不能看到任何变化,因为重新绘制将在该持续时间内绘制相同的点(1 sec)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2019-02-18
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2021-05-29
    • 1970-01-01
    相关资源
    最近更新 更多