QCustomPlot Discussion and Comments

cannot change tickerReturn to overview

Hi
I am trying to put a second axis on top of a colormap and a second axis on the right.
My issue is that the manipulation of the ticker structure is non obvious
I can see the tick labels by accessing
ui->plot->xAxis2->tickVectorLabels()
but I cannot change the content of them, not substitute the vector with an empty vector.
I tried by providing a new ticker through ui->plot->xAxis2->setTicker( fixedTicker )
( I set up the fixedTicker before) but the issue is that now there are two tick labels vectors displayed, one with numbers 0..5 which I can't manipulate nor remove, and another with the desired value.
How can I get rid of this second tick labels vector?

I forgot to add, I am using QCustomplot as of 25.06.18 - Version 2.0.1

The methods tickVector and tickVectorLabels are only for read purposes, that's why they return a QVector by value.
The correct way to influence the ticks is by the ticker, have a look at the QCPAxisTicker documentation.

The fact that you see a second set of ticks can have multiple reasons, we'd need to see your code to say what's actually going wrong (A screenshot would also be helpful). Possibly you have created two axes on top of each other (forced offset of 0), or used a strange QCPAxisTicker subclass.

Do you know that you already have an axis to the right and at the top? They are just invisible by default. You can set them to visible with yAxis2->setVisible(true), same with xAxis2. Alternatively, have a look at setupFullAxesBox.

Here you can see my problem: https://pasteboard.co/JjRWjW5.png
Indeed I saw a spurious
ui->plot->axisRect()->addAxis(QCPAxis::atRight)
as I understand your comment, this effectively adds a further axis next to the already invisible one, am I right? how will this be accessible then? as yAxis3?
Regards

The default four axes of the main axis rect have pointers for convenience (xAxis, yAxis, xAxis2, yAxis2). All other additional axes either on the main axis rect or on additional axis rects can be accessed via axisRect->axis(...). This is also demonstrated in the Advanced Axes Demo

Quoting from the QCPAxisRect documentation:

By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be accessed via QCPAxisRect::axis by providing the respective axis type (QCPAxis::AxisType) and index. If you need all axes in the axis rect, use axes. The top and right axes are set to be invisible initially (QCPAxis::setVisible). To add more axes to a side, use addAxis or addAxes. To remove an axis, use removeAxis.

Hi,
I removed the spurious ui->plot->axisRect()->addAxis(QCPAxis::atRight) and the extra axis disappeared. Now there's a minor issue left: on one axis the ticks show numbers from 16 to 30, on the other from 16 to 28. It looks like there's some kind of rounding error, in both cases the ranges are 15 to 29,9 and these values should be displayed. How to fix this?
regards

Did you look at setupFullAxesBox? This will link the ranges. Right now your left and right axis ranges are completely independent and set to different lower/upper bounds, and your map is only associated with the left axis.

If you want you can also link the ranges manually via rangeChanged and setRange.

If I look at your image, you might even want to insert a slot in between that does a transformation from pixels to latitude/longitude. So just connect a custom slot to rangeChanged, and there calculate the according other axis upper/lower bound, and call its setRange with those values.

hi
I found myself the solution: to rescale the axes to rounded values, and to set the tick step to 2,5 instead of 2.
the ticker shows only integer values (as specified actually) and apparently the ticks start from 0, not from the axis lower bound.
I will take a look at setupFullAxesBox, thanks!

The ticks start (mathematically) from the specified origin, which indeed by default and for most use cases makes sense to be 0. Feel free to change it though if you require: xAxis->ticker()->setTickOrigin.

Make sure to change that on both axes, so they stay in sync (or have them share a mutual axis ticker from the start, using setTicker with a common QSharedPointer).

Hi
basically I did this:

  // set a new Ticker for the upper X Axis
  QSharedPointer<QCPAxisTickerFixed> fixedLatitudeTicker(new QCPAxisTickerFixed);  
  fixedLatitudeTicker->setTickStep(2.5); // tick step shall be 1.0
  fixedLatitudeTicker->setScaleStrategy(QCPAxisTickerFixed::ssNone); // and no scaling of the tickstep (like multiples or powers) is allowed

  ui->plot->xAxis2->setTicker(fixedLatitudeTicker);
  ui->plot->xAxis2->setTickLabels(true);
  ui->plot->xAxis2->setTicks(true);
  
  // set a new Ticker for the right Y Axis
  QSharedPointer<QCPAxisTickerFixed> fixedLongitudeTicker(new QCPAxisTickerFixed);  
  fixedLongitudeTicker->setTickStep(2.5); // tick step shall be 1.0
  fixedLongitudeTicker->setScaleStrategy(QCPAxisTickerFixed::ssNone); // and no scaling of the tickstep (like multiples or powers) is allowed

  ui->plot->yAxis2->setTicker(fixedLongitudeTicker);
  ui->plot->yAxis2->setTickLabels(true);
  ui->plot->yAxis2->setTicks(true);

the ticks are now correct. Then I added zoom and pan by

  ui->plot->setInteraction(QCP::iRangeDrag, true);
  ui->plot->setInteraction(QCP::iRangeZoom, true);

and as soon as I pan or zoom with the mouse, the original ticks overwrite mine and because of the small tick step, they make a sequence of overlapping strings, which appear as a black stripe. When zooming in the ticker text becomes visible again, but my custom made tickers are gone.

How can I have my custom ticks being drawn after a zoom/pan action?
thanks

also the colorbar is not updated, how to connect it to the zoom?

I see now that the zoom and pan on the colorscale already works, just it's not in sync with the colormap. So basically zooming in schows a part of the colormap, but the colorcsale does not get automatically redrawn.

But more important, I have no idea about how to preserve the custom ticks while zooming in/out, as the axis shows the default one ( the pixel index)