3

I use QCustomPlot to display histograms of pictures. The function I use to set the a curve is the following:

void SingleHistogram::setHist(const QVector<double> &x,
                              const QVector<double> &y)
{
    //clearGraphs();
    graph(0)->setData(x, y);
    graph(0)->rescaleAxes(true);
    replot();
}

It works great for the first picture I open:

enter image description here

But when I set a new histogram using the same function, the first curve is not removed (even if setData() calls clearData() method of the graph) :

enter image description here

As you can seen the second curve (the peak) is added to the graph.

I'd like not to delete and reconstruct a new QCPGraph for efficiency since I feel like it is useless.

Could someone tell me what I am doing wrong here?

Thanks!

Community
  • 1
  • 1
Plouff
  • 3,290
  • 2
  • 27
  • 45

2 Answers2

0

Just out of curiosity, are you clearing your vectors x,y? if not you should clear them before loading new graph.

code will look somewhat like

// Graph 1    
setHist(x,y);  // set graph

//
// ..Some code
//

//before loading new values
x.clear();
y.clear();

// Graph 2 
// Fill up new values
// x=[],y=[]

// set NEW graph
setHist(x,y);
Mandar
  • 1,006
  • 11
  • 28
0

Actually, I found that the input data I provided the graph contained 2 sets of values. So each x coordinate had 2 y values.

It's interesting to know that QCustom plot will produce this kind of graph in this case!

Plouff
  • 3,290
  • 2
  • 27
  • 45