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

                                     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...

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

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,

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.


I have a similar problem when using QCPCurve with the latest version QCustomplot 2.0.0-beta. On Windows I can add one "plottable". When I clear the Curves and load it again, the Curve's Scatter Symbols will not be drawn, except the first one. The data is available and if I don't use QCPCurve::lsNone for the LineStyle, the data is connected with lines correctly.
I somehow managed to solve the problem by changing the layout of my Window ( I have a pushbutton, a ListView and a Widget used for QCustomPlot ). By changing the layout, sometimes more than one ScatterSymbol was shown and after some more (arbitrary) changes, I showed all ScatterSymbols.

However, I had to port the project from Windows to Linux-Ubuntu14.04x64 and there the same problem occured. No matter which layout I'm using, only the first ScatterSymbol is shown. Further, it occurs directly with the first time I'm loading a plottable.
Replot and rescaling the axis does not help.

I also have to use QCPCurve to plot the data in the correct order as I need the interaction with the plot and the order is important in my case.

Maybe my problem is connected to Roman W's problem.


I just solved my problem. I seems that the variable mScatterSkip is not initialized. On Windows the default value was some big negative number. On Linux the number was 272. Therefore, my ScatterSymbols were skipped on Linux but not on Windows.
I use the method setScatterSkip(0) to make sure that the value is 0. In that case all data is plotted.

Hi Michael,

This is a known bug in the beta and already fixed in the final. I'm afraid the problem of the thread starter isn't related to mScatterSkip, as far as I can tell.

had same annoying problem of randomly not showing scatter symbols.
setScatterSkip(0) solved my problem too! Thanks for the hint, Michael, you made my day! ;)

@DerManu: As far I can see, there is still no final release of version 2.0.0. Is this bug fixed already in dev-2.0.0 branch on github?

Yep: https://gitlab.com/DerManu/QCustomPlot/commit/cd1f5d347b8a9cc21f357f08a207d58618fc4cba