Qt - How do I define the spacing of the axes on a QCustomPlot?

I am using QCustomPlot

, on Qt, to display aspects of a video sequence.

I would like to define the background of my graph in order to define specific zones along mine yAxis

. My schedule is like this:

My plot (example)

And I would like to define the intervals in mine yAxis

to get something like this:

enter image description here

The last image is from a program called PEAT, which is used to analyze videos that can cause epileptic seizures. I point out that they define zones along yAxis

.

Any suggestions?

+3


source to share


1 answer


To have an area on the chart, you can add two plots that define the boundaries of the area:

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

      

Then you can fill in the area between the borders using setChannelFillGraph

:

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

      



Also don't forget to assign appropriate values ​​for the borders:

  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 borders, for example in your example.

+5


source







All Articles