QCustomPlot Discussion and Comments

scatter plot not respecting adaptiveSampling false with scatterStyle ssDotReturn to overview

Hi,
for a performance evaluation I was plotting the same data, with
customPlot->graph( 0 )->setScatterStyle( QCPScatterStyle( QCPScatterStyle::ssCircle, 1 ) );
and
customPlot->graph( 0 )->setScatterStyle( QCPScatterStyle( QCPScatterStyle::ssDot, 1 ) );
both with
customPlot->graph( 0 )->setAdaptiveSampling( false );
The graph with ssCircle looks good, and is a bit slothy, but that was expected, while the graph with ssDot is faster, which was also expected, but the graph looks way too thin (not expected) and the data changes appearance while resizing (not expected).

see https://ibb.co/Fbc6KG9

The right images are after a minimal change of width. The top is ssDot, the bottom is ssCircle. As you can see, there is a visible difference between the top two. Am I doing something wrong, is this a bug, or is this possibly even the intended behavior?

Data is just a normal distribution:

 std::normal_distribution<> d{5, 2};
 int const num = 100000;

  QVector<double> x0,y0;
  x0.resize( num );
  y0.resize( num );
  for( int n = 0; n < num; ++n ) {
    x0[n] = d( gen );
    y0[n] = d( gen );
  };

I think I tracked down the cause of the problem. To me it looks like a bug. I fixed it to work the way that I expect by switching from drawLine to drawPoint

void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const
{
    ...
    case ssDot:
    {
      //painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y));
      painter->drawPoint(QPointF(x, y));
      break;
    }
    ...
}

The reasoning for this is that Qt has a bug in some versions/on some platforms where the drawPoint method simply doesn't result in anything visible on the screen, and on other platforms a line over the entire length of the canvas. For at least some versions the bugfix in Qt's own code was to have drawPoint draw a Line with a tiny length, which I adopted directly into QCP code because it needs to run on all Qt versions from 4.6 to current ones, and on all associated platforms, evening out all Qt bugs in that timeline.

I'm surprised that this line drawing seems to fail again now. Could you tell me which Qt version and which platform you're using? I might need to put a compiler define for this method to catch that combination of yours.

If you have time/are interested to try it out: Does the drawLine code work as expected if you change the length of the line, like so:

painter->drawLine(QPointF(x, y), QPointF(x+0.5, y));

// For reference some discussions about Qt's drawPoint behaviour:
StackOverflow,
Bugreport,
QtCentre

My System is :
Microsoft Windows 10 Pro Build 17134
Qt is Version 5.12.0 msvc 2017 64-bit

Changing the draw code to

painter->drawLine(QPointF(x, y), QPointF(x+0.5, y));

also works for me.

The results with drawLine are suboptimal. The plots look blurred.

https://ibb.co/vzz1cwh

Therefore I don't think that this should be the default. The default should be drawPoint with a fallback to drawLine on problematic platforms.

Another reason this should not be the default is that it is about a factor 2x slower.