QCustomPlot Discussion and Comments

Any suggestion for putting tick and tick labels besides zero lines?Return to overview

Hi,
I have a question. If i want to put tick and tick labels besides zero line, how can i achieve that? What's your suggestions?
see this: http://www.ffconsultancy.com/products/fsharp_for_visualization/demo4.html

Hi Mostafa,

I'm afraid there's currently no easy way of doing that. However I've just come up with a nice hack:
in a slot connected to the signal QCustomPlot::beforeReplot, call

  int pxx = mCustomPlot->yAxis->coordToPixel(0);
  int pxy = mCustomPlot->xAxis->coordToPixel(0);
  mCustomPlot->xAxis->setOffset(-mCustomPlot->axisRect()->height()-mCustomPlot->axisRect()->top()+pxx);
  mCustomPlot->yAxis->setOffset(mCustomPlot->axisRect()->left()-pxy);

This uses the axis offset feature, to place the axes at the according coordinates. Note however that this really is a hack and not what the offset feature was meant to be used for. So accordingly it might need some extra work. For example, it doesn't seem to work smoothly if scrolling the origin out of view to the bottom or left. This is because increasing the axis offsets outwards pushes away the axis rect to make the axis stay in view. You can fix this behaviour by disabling automatic margin calculation on the axis rect via
customPlot->axisRect()->setAutoMargins(QCP::msNone);

Maybe by playing around you'll find a way to make it perfect.

Special thanks for you Emanuel. :)

works very well, except when using in a in floating widget, after resizing the axis are not centered anymore, have to click on the widget to get the axis realigned.

any idea how to fix this ?

int pxx = mCustomPlot->yAxis->coordToPixel(0);
pxx is always -1
why?