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:
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) :
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!
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);
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.