QCustomPlot Discussion and Comments

logarithmic scale is not correct.Return to overview

QCustom plot is extremely impressive. Recently I faced a problem with logarithmic scale. When I set the scale to logarithmic and plot data points, the spacing of major grid lines at 10,100,1000... are correct, but the spacing of minor grid lines are not correct. However the datapoints are marked in correct locations. Minor axis grid does not coincide with the data value. Let's say, if I plot (20,4), it shows the point at (20,4), but it does not fall on the the minor axis grid 20. I confirmed the location of point as correct by comparing the plot with MATLAB. So problem lies in the plotting of the minor axis grid lines. Please resolve it.

Well something like this would have been fixed long ago. There's a problem in your code, if you show it maybe we can figure it out.

Have a look:

http://www.qcustomplot.com/images/forum/log-subticks.png

  QCPGraph *g = customPlot->addGraph();
  g->setScatterStyle(QCPScatterStyle::ssDisc);
  
  for (int i=10; i<=100; i+=10)
  {
    g->addData(i, i);
    QCPItemText *text = new QCPItemText(customPlot);
    customPlot->addItem(text);
    text->setText(QString::number(i));
    text->position->setCoords(i+4, i);
  } 
  
  customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
  customPlot->yAxis->grid()->setSubGridVisible(true);
  customPlot->yAxis->grid()->setSubGridPen(QPen(Qt::black, 1, Qt::DotLine));
  customPlot->yAxis->grid()->setPen(QPen(Qt::black, 1, Qt::DotLine));
  customPlot->yAxis->setSubTickCount(8);
  customPlot->rescaleAxes();

My guess is you miscounted sub tick count or are associating a wrong axis with your data.

Thanks for the reply... You are correct... I had set the setSubTickCount to 10 instead of 8.

This instruction customPlot->addItem(text); not working

You can just remove the addItem line here, it is not needed in newer QCustomPlot versions.