Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:31:27+00:00 2026-06-08T23:31:27+00:00

I was going to provide a screenshot of my core plot graph for reference

  • 0

I was going to provide a screenshot of my core plot graph for reference but I’m not allowed to yet (new user) so I can email it upon request.

I have a set of data points, with x values of 1 to ~150, and y values of ~300 to ~450.
What I would like to do is plot these points, with a clean grid overlay, zooming in on the
y Axis (graph y axis should start from y min, rather than 0, and go to y max), while still retaining a visible x-axis for referencing purposes.

I’m fairly close to achieving what I want, but I’m still struggling with a few things.

First of all, I would like a label on the y axis at the intersection between the y axis and x axis, and at the top of the y axis, in order to give the user a point of reference.

To achieve this, I’ve started by playing around with major tick intervals, as well as running a few operations on my data set to determine max and mins. However, when I then attempted to zoom in (i.e. focus on the range between y-min and y max), the x axis was no longer visible.

To fix this, after some searching across the net I came across:

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];

While this seems to force the x-Axis to appear, it also seems to be throwing my graph off a bit… there are only 3 minor ticks between my first y-axis major tick, and the origin, and no y-Axis label on the origin.

Does anyone know how to achieve this offset, while forcing the origin to be the first major tick, and display labels for the y-Axis at both the origin and y-Max?

As a side question, does anyone know how to display the x-Axis labels as ints rather than floats (looking to cut off the decimal)?

I’ll throw my source code for what I’ve achieved so far below.

Thanks,

Brandon

Source Code for initialize plot:

-(void)initialisePlot {

[self setDataMaxAndMins];

// Create a graph object which we will use to host just one scatter plot.
CGRect frame = [self.hostingView bounds];
self.graph = [[CPTXYGraph alloc] initWithFrame:frame];

// Add some padding to the graph, with more at the bottom for axis labels.
self.graph.plotAreaFrame.paddingTop = 50.0f;
self.graph.plotAreaFrame.paddingRight = 50.0f;
self.graph.plotAreaFrame.paddingBottom = 100.0f;
self.graph.plotAreaFrame.paddingLeft = 120.0f;

// Tie the graph we've created with the hosting view.
self.hostingView.hostedGraph = self.graph;

self.hostingView.backgroundColor = [UIColor blackColor];

// Create a line style that we will apply to the axis
CPTMutableLineStyle *axisStyle = [CPTMutableLineStyle lineStyle];
axisStyle.lineColor = [CPTColor grayColor];
axisStyle.lineWidth = 2.0f;


CPTColor * customGray = [CPTColor colorWithComponentRed:0.6f green: 0.6f blue: 0.6f alpha: 1.0f];
CPTMutableLineStyle *gridStyle = [CPTMutableLineStyle lineStyle];
gridStyle.lineColor = customGray;
gridStyle.lineWidth = 2.0f;

//Create plot symbol style
CPTMutableLineStyle * plotStyle = [CPTMutableLineStyle lineStyle];
plotStyle.lineColor = [CPTColor whiteColor];
plotStyle.lineWidth = 2.0f;

// Create a text style that we will use for the axis labels.
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.fontName = @"Helvetica";
textStyle.fontSize = 20;
textStyle.color = [CPTColor whiteColor];

// Create the plot symbol we're going to use.
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.lineStyle = plotStyle;
plotSymbol.size = CGSizeMake(3.0, 3.0);
//plotSymbol.


// Setup some floats that represent the min/max values on our axis.
float xAxisMin = xMin;
float xAxisMax = xMax + 5;
float yAxisMin = yMin;
float yAxisMax = yMax + 5;

// We modify the graph's plot space to setup the axis' min / max values.
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];

// Modify the graph's axis with a label, line style, etc.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;

axisSet.xAxis.title = xAxisTitle;
axisSet.xAxis.titleTextStyle = textStyle;
axisSet.xAxis.titleOffset = 50.0f;
axisSet.xAxis.axisLineStyle = axisStyle;
axisSet.xAxis.majorTickLineStyle = axisStyle;
axisSet.xAxis.minorTickLineStyle = axisStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat((xAxisMax - xAxisMin) / 4);//CPTDecimalFromFloat(25.0f);
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;


axisSet.yAxis.title = [yAxisTitle stringByAppendingString: @" ($M)"];

axisSet.yAxis.titleTextStyle = textStyle;
axisSet.yAxis.titleOffset = 80.0f;
axisSet.yAxis.axisLineStyle = axisStyle;
axisSet.yAxis.majorTickLineStyle = axisStyle;
axisSet.yAxis.minorTickLineStyle = axisStyle;
axisSet.yAxis.labelTextStyle = textStyle;
axisSet.yAxis.labelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = CPTDecimalFromFloat((yAxisMax - yAxisMin) / 4);
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;

CPTColor * customLighterBlue = [CPTColor colorWithComponentRed:0.0f green: 0.0f blue: 0.4f alpha: 1.0f];
CPTColor * customDarkBlue = [CPTColor colorWithComponentRed:0.0f green: 0.0f blue: 0.3f alpha: 1.0f];
axisSet.xAxis.alternatingBandFills = [NSArray arrayWithObjects:customLighterBlue, customDarkBlue, nil];

axisSet.xAxis.majorGridLineStyle = gridStyle;

axisSet.yAxis.majorGridLineStyle = gridStyle;

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];


// Add a plot to our graph and axis. We give it an identifier so that we
// could add multiple plots (data lines) to the same graph if necessary.
CPTScatterPlot *plot = [[CPTScatterPlot alloc] init];
plot.dataSource = self;
plot.identifier = @"mainplot";
plot.dataLineStyle = nil;
plot.plotSymbol = plotSymbol;
[self.graph addPlot:plot];

//[_graph.defaultPlotSpace scaleToFitPlots:[_graph allPlots]];

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:31:29+00:00Added an answer on June 8, 2026 at 11:31 pm
    1. Change the labeling policy. I think CPTAxisLabelingPolicyEqualDivisions will do what you want. There is a demo in the Plot Gallery example app that shows all of the available labeling policies.

    2. Set the labelFormatter on the x-axis. It is a standard NSNumberFormatter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to try to explain this best I can I will provide more
I'm going to ask how it's done in c++, but this idea can apply
I'm attempting to provide a confirmation link in my user welcome email and I'm
I'm not going to provide the code because it's too long. The python script
Basically I am not going to post all of the code here but I
I'm going to create a new add-on for my n2 based website, but I
I am going to write a text editor in Qt which can provide highlighting/code
I'm going to make a files, resources manager for user. My website provide a
I'm going to implement on my site a OAuth Provider, but I'm little confused:
may be i am going to ask some stupid question but i don't have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.