I have implemented the logic of recalculation of some coordinates in the method connected to the QCustomPlot::beforeReplot signal. Now the QCustomPlot::replot method looks like this:

void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority)
  emit beforeReplot();

If the position of the axes was not valid, the coordinates will be recalculated incorrectly.
I suggest calling the updateLayout() method before the signal beforeReplot()