In an androidplot XYPlot, the tick labels on the Y axis get clipped if you have large values (many digits) and/or a large font size. This (and similar issues on the X axis) has been discussed before in these questions:
The answer is always to add more padding and/or margin in order to have enough space for the labels.
My question is: How can I set the padding/margin to have just the right amount of space?
Simply hardcoding the left margin to some value is a suboptimal solution. Let's assume I want to plot some data and I don't know in advance if the Y values will be in the range [0,9] or in the range [10000,20000]. How can I set the padding/margin to avoid both clipping and unnecessary empty space?
The best workaround I could find was this:
int digits = (int) Math.floor(Math.log10(absmax)) + 1;
float leftpad = digits * fontsize/2;
myplot.getGraphWidget().setPaddingLeft(leftpad);
Where absmax is the greatest absolute value in the data.