0
votes

In my scatter plot, I use Core-Plot's autoscale feature, which seems to work fine, according to my test plots (see below):

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
[plotSpace scaleToFitPlots:[NSArray arrayWithObject:sharePricePlot]];
[valuationPlotSpace scaleToFitPlots:[NSArray arrayWithObject:valuationPlot]];

CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];

[xRange expandRangeByFactor:CPTDecimalFromDouble(1.0)];
[yRange expandRangeByFactor:CPTDecimalFromDouble(1.0)];
plotSpace.xRange = xRange;
plotSpace.yRange = yRange;

I use custom labels for my x-axis which I set in an standard enumeration. In this enumeration, I set each axis label based on the demo app as follows:

CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%u", year]
textStyle:xAxis.labelTextStyle];
newLabel.tickLocation = CPTDecimalFromUnsignedInteger(idx);
newLabel.offset = 0;
[xAxisLabels addObject:newLabel];

However, even though I set the offset to 0, which should position the labels very close to the x-axis (in my view), the offset between the axis and the labels is different depending on the range of y-values (please refer to the charts for Amazon and Priceline below).

How can I set the distance between the x-axis and the labels independent of the (auto-scaled) y-values?

Chart 1: Amazon Amazon

Chart 2: Priceline Priceline

THANK YOU!

1

1 Answers

5
votes

It looks the whole x-axis is moving. You can fix it in place using constraints.

x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];