QCustomPlot Discussion and Comments

BUG? -- axisRectReturn to overview


I was creating a widget with a ratio of 1:2. For example the height was 200px and the width was 400px. Furthermore I was plotting a (plottable) square (same sides).

If I want to calculate the ratio of my widget it would look like:

ratio = ui->chart->axisRect()->width()/ui->chart->axisRect()->height();
>> 2

But if there is a plot with a x,y-Axis there would be an offset due to each axis. Means: The x-Axis has already an offset aswell as the y-Axis has an offset to the widget.

Now, if I would use the 'setScaleRatio(yAxis, ratio)' with a factor of 2 it will lead to a wrong stretch.

And: If I would like to recalc the scaleRatio by hand I have no chance to obtain the perfect values because there is no chance to
- either move the axis to the border of the widget
- get the (correct) margins/offset (axis) to the widget
- have a function that would calculate the correct values
- use setVisiblity (yaxis, xaxis) to false because the (min) offset is fixed by default?

Maybe I'm doing it wrong?



Hi Peter,
As you can see in the code, QCPAxis::setScaleRatio correctly uses the axis rect width and height, and thus isn't influenced by any margin. Note that width/height of an axis rect is the "inside" rect, not including any labels, offsets or paddings.

How are you using setScaleRatio, and what exactly doesn't work the way you expect it to?

I was trying to plot a square (a=b). But I couldnt get the right aspect ratio. My qcustomplot widget has a 1:2 (y:x) ratio. The graph itself has a different size compared the the widget. The setScaleRatio would do fit it but it sets the ratio for the graph and the ratio is not 1:2 due to offsets. In other words the innerRect values of that plot (reading the documentation) would be the values I'm looking for. But how can I obtain these? The rectAxis is only providing the outer size (->widget) and not the inner size (->plot).



Edit: Seems to be a problem on my side. I've got the inner rect and its working because it has the same aspect due to a constant margin.

Btw: How can I reduce the size of the outer margin?