Search code examples
ios5core-plotiphone-4

iOS5 Core Plot fit plot to visible area


I got a plot for which I defined the Y range as -2000 to 2000

 plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(1) length:CPTDecimalFromInt(600)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2000) length:CPTDecimalFromInt(2000)];

The plot is fitted to the graph along the X axis, causing the majority of the Y axis to be cut off. How can I ask the core plot to autoscale the Y axis to make the maximum value in a series just touch the top of the screen?

Thank you!


Solution

  • Plot ranges are defined by a location and a length, similar to NSRange. To make a range that spans between -2000 and 2000, your yRange should have a location of -2000 and length 4000.

    You can autoscale a plot space using the -scaleToFitPlots: method. Several of the Core Plot example apps use this method to fit plots to their data.