C++ Qt-如何在QCustomPlot上定义轴间隔?

C++ Qt-如何在QCustomPlot上定义轴间隔?,c++,qt,qt5,axis,qcustomplot,C++,Qt,Qt5,Axis,Qcustomplot,我在Qt上使用QCustomPlot,来绘制视频序列的各个方面 我想定义图形的背景,以便定义沿我的yAxis的特定区域。 我的图表如下: 我想在我的yAxis中定义间隔,以得到如下结果: 最后一幅图像属于一个名为PEAT的程序,该程序用于分析可能引发癫痫发作的视频。我指的是它们沿yAxis定义区域的方式 有什么建议吗?要在绘图中有一个区域,可以添加两个定义区域边界的图形: //Upper bound customPlot->addGraph(); QPen pen; p

我在Qt上使用
QCustomPlot
,来绘制视频序列的各个方面

我想定义图形的背景,以便定义沿我的
yAxis
的特定区域。 我的图表如下:

我想在我的
yAxis
中定义间隔,以得到如下结果:

最后一幅图像属于一个名为PEAT的程序,该程序用于分析可能引发癫痫发作的视频。我指的是它们沿
yAxis
定义区域的方式


有什么建议吗?

要在绘图中有一个区域,可以添加两个定义区域边界的图形:

  //Upper bound
  customPlot->addGraph();
  QPen pen;
  pen.setStyle(Qt::DotLine);
  pen.setWidth(1);
  pen.setColor(QColor(180,180,180));
  customPlot->graph(0)->setName("Pass Band");
  customPlot->graph(0)->setPen(pen);
  customPlot->graph(0)->setBrush(QBrush(QColor(255,50,30,20)));

  //Lower bound
  customPlot->addGraph();
  customPlot->legend->removeItem(customPlot->legend->itemCount()-1); // don't show two     Band graphs in legend
  customPlot->graph(1)->setPen(pen);
接下来,您可以使用
setChannelFillGraph
填充边界之间的区域:

  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
另外,不要忘记为边界指定相关值:

  QVector<double> x(250);
  QVector<double> y0(250), y1(250);

  for (int i=0; i<250; ++i)
  {
      x[i] = i ;
      y0[i] = upperValue;

      y1[i] = lowerValue;

  }
  customPlot->graph(0)->setData(x, y0);
  customPlot->graph(1)->setData(x, y1);
qx矢量(250);
矢量y0(250),y1(250);
对于(inti=0;igraph(0)->setData(x,y0);
自定义绘图->图形(1)->设置数据(x,y1);

您也可以添加其他图形来显示一些边界,如示例中的边界。

非常感谢您的回答,您的建议解决了我的问题。但我无法显示文本“通带”在绘制的图形上,知道为什么会发生这种情况吗?@NelsonR示例中的辅助名称显示在图例中。要在绘制的图形上显示文本,应使用
QCPItemText
。有关示例,请参阅感谢您的帮助,您建议的示例效果很好。