3

I'm using QCustomPlot, on Qt, to plot aspects of a video sequence.

I would like to define the background of my graph in order to define specific zones along my yAxis. My graph is this:

My plot (example)

And i would like to define intervals in my yAxis to get something like this:

enter image description here

The last image belongs to a program called PEAT, used to analyse videos that can trigger epilepsy seizures. I am pointing to the way that they define the zones along the yAxis.

Any suggestions?

Nejat
  • 31,784
  • 12
  • 106
  • 138
NelsonR
  • 35
  • 4

1 Answers1

5

To have a region in the plot, you can add two graphs which define the bounds of the region :

  //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);

Next you can fill the area between the bounds using setChannelFillGraph :

  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));

Also don't forget to assign the relevant values for the bounds :

  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);

You can also add other graphs to show some boundaries like the one in your example.

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • Thank you very much for you answer, your suggestion solves my problem. But I'm not being able to show the text "Pass Band" on the plotted graph, any idea why is this happening? – NelsonR Sep 02 '14 at 14:14
  • 1
    @NelsonR The assined name in the example is shown in the legend. To show the text on the plotted graph you should use `QCPItemText`. For an example see http://www.qcustomplot.com/index.php/tutorials/items – Nejat Sep 02 '14 at 15:43
  • Thanks for your help, the example you suggested worked just fine. – NelsonR Sep 03 '14 at 02:52