QCustomPlot Discussion and Comments

Issue with displaying unconnected points using QCPCurveReturn to overview

Hi there,

I am using QCPCurve to display a number of 2D coordinates (no lines in between) in a plot using QCustomplot 2.0.0-beta. When I developed the code on a Raspberry Pi with Qt 4.something, everything worked smoothly and the points were all displayed correctly. However, when migrating to another Linux system running Qt 5.7, only the first of 60 evenly spread points is displayed (see https://www.dropbox.com/s/kgx66npyw178ht5/graph.png?dl=0). I verified the data and everything seems correct, so I don't really know what's going on.

I created a class that inherits from QCustomPlot, which contains the private member

QCPCurve* accesspoints_;

The object is initialized in the constructor's initialization list with accesspoints_(new QCPCurve(this->xAxis, this->yAxis)). In the constructor I then apply some adjustments to the QCustomplot-instance and the QCPCurve instance:
this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
this->axisRect()->setupFullAxesBox();

this->accesspoints_->setName("Accesspoints");
this->accesspoints_->setLineStyle(QCPCurve::lsNone);
this->accesspoints_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssSquare, 
                                     QColor("#000080"), QColor("#6495ED"), 10));

After that, a method is called to add the points from same other class. This is done only once:
for (const t_accesspoint_map::value_type& ap : rmap->getAccesspoints())
{
  accesspoints_->addData(accesspoints_->dataCount(), ap.second->x(), ap.second->y());
  // I verified the loop and the coordinates using std::cout, everything is fine...
}
this->replot();

At this point, this->accesspoints_->data()->size() is, as expected, 60. Finally, a method zoomToMaxExtent() is called to update the view. It contains:
this->rescaleAxes();
this->xAxis->scaleRange(1.05, this->xAxis->range().center());
this->yAxis->scaleRange(1.05, this->yAxis->range().center());
this->replot();

Interestingly, the scaleRange() method seems to be aware of all the 60 points, since the visible area matches the area where points should be displayed.


Since I am new to QCustomPlot and also to Qt, I don't really know what could be the issue here. Could it be the Qt version? Should I try QCustomPlot 1.3.2? Is there something like adaptive sampling for QCPCurve which could be the issue?


Thanks for helping me out,
Roman

Okay so I still got no solution for my problem but I will just post my findings so far:

It looks like the plotting of features is messed up as soon as there is a QTabWidget somewhere in my form. It doesn't even matter if the QCustomPlot instance or any connected UI controls are within said QTabWidget; as long as it's there (even completely empty and non-functional), the plot behaves weird.

At this point I'm not sure if this is true only for the QTabWidget, but I've tried some other widgets and I could reproduce the issue only with the QTabWidget.


Can anyone report a similar or related behavior? I will keep posting updates here (if there are any) for future reference...

Appendix. I added screenshots of the reproduced phenomenon:

All working nicely: https://www.dropbox.com/s/ci6gfn732u4cc7s/chart_ok.png?dl=0
Not so much: https://www.dropbox.com/s/hvnb4ac7msj6h0r/chart_error.png?dl=0

Hi Roman,

Did you check your application for memory errors, e.g. with valgrind? Does this also happen with absolutely simplistic code, i.e. only a QMainWindow, on it a QCustomPlot and those few lines above for the static data generation?

Does it also happen with QCPGraph or only with QCPCurve? (Although using QCPGraph will change the memory layout and thus this test can't rule out there's something funky going on with memory). Regarding your question about optimization: QCPCurve doesn't use adaptive sampling as QCPGraph, however it uses a moderately sophisticated geometry reduction on off-screen curve vertices.

I suggest you step through the code or put some qDebug outputs in the QCPCurve drawing code (especially getScatters, draw, and drawScatterPlot) and find out whether it iterates through all the points that you expect. Depending on that we can pinpoint the issue a bit better.

//EDIT: By the way, I can't reproduce the issue myself here, otherwise I'd of course be debugging it myself. Is there any chance you could upload or send me the raw data coordinates or data generation code so I can replicate your situation better?

The screenshots I provided are indeed a minimum (non-)working example. The data is loaded correctly. Since I am plotting corrdinates, I can't really use QCPGraph because of possible duplicate x/y values.

I don't really have the time now to further dig up a solution for my problem, instead I redesigned my GUI (for the better, anyways) to get rid of the QTabWidget and it seems to behave for now.


Thanks for your input though, if I should by chance stumble upon further insights I will post them here. I still put the blame on my Linux distro in use, since it works fine on other machines.

FYI: QCPGraph can handle doubling x/y values. Just when you connect them with lines, you'll have a line drawing order from lower x to higher x. But since you only use scatters that doesn't affect you.