我有core-plot的基本散点图,y轴似乎正常工作。似乎为了获得一个x轴标签,我必须添加很多paddingBottom
,这也使我的情节得到了大约三分之一。当我的填充不是250(应该更像是50)时,我的x轴标签不在哪里。它就消失了。
#define X_MIN (0)
#define X_MAX (1000)
#define X_INTERVAL (250)
#define X_TITLE_OFFSET (30)
#define X_TITLE_PADDING (250)
#define Y_MIN (9000)
#define Y_MAX (13000)
#define Y_INTERVAL (500)
#define Y_TITLE_OFFSET (50)
#define Y_TITLE_PADDING (50)
- (void)viewDidLoad {
NSLog(@"viewDidLoad");
plotXMinRange = X_MIN;
plotXMaxRange = X_MAX;
plotXInterval = X_INTERVAL;
plotYMinRange = Y_MIN;
plotYMaxRange = Y_MAX;
plotYInterval = Y_INTERVAL;
[self initLinePlot];
}
-(void)initLinePlot {
// Initialize and display Graph (x and y axis lines)
self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphView.bounds];
self.hostView = [[CPTGraphHostingView alloc] initWithFrame:self.graphView.bounds];
self.hostView.hostedGraph = self.graph;
[self.graphView addSubview:hostView];
// Apply styling to Graph
[self.graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
// Set graph backgound area transparent
self.graph.backgroundColor = nil;
self.graph.fill = nil;
self.graph.plotAreaFrame.fill = nil;
self.graph.plotAreaFrame.plotArea.fill = nil;
// Remove top and right lines of graph
self.graph.plotAreaFrame.borderLineStyle = nil;
self.graph.plotAreaFrame.masksToBorder = NO;
// Configure graph paddding
self.graph.paddingBottom = X_TITLE_PADDING;
self.graph.paddingLeft = Y_TITLE_PADDING;
self.graph.paddingRight = 0;
self.graph.paddingTop = 0;
// Configure x and y axis range
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = NO;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(plotXMinRange)
length:CPTDecimalFromInt(plotXMaxRange - plotXMinRange)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(plotYMinRange)
length:CPTDecimalFromInt(plotYMaxRange - plotYMinRange)];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
NSNumberFormatter *axisLabelFormatter = [[NSNumberFormatter alloc] init];
[axisLabelFormatter setGeneratesDecimalNumbers:NO];
[axisLabelFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
// Configure x-axis properties
axisSet.xAxis.majorIntervalLength = CPTDecimalFromInt(plotXInterval);
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTickLength = 5;
axisSet.xAxis.majorTickLength = 7;
axisSet.xAxis.title = @"Time [s]";
axisSet.xAxis.titleOffset = X_TITLE_OFFSET;
axisSet.xAxis.labelFormatter = axisLabelFormatter;
// Configure y-axis properties
axisSet.yAxis.majorIntervalLength = CPTDecimalFromInt(plotYInterval);
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTickLength = 5;
axisSet.yAxis.majorTickLength = 7;
axisSet.yAxis.title = @"Total Volume [mL]";
axisSet.yAxis.titleOffset = Y_TITLE_OFFSET;
axisSet.yAxis.labelFormatter = axisLabelFormatter;
// Configure line plot and set line properties
self.linePlot = [[CPTScatterPlot alloc] init];
self.linePlot.dataSource = self;
[self.graph addPlot:self.linePlot toPlotSpace:plotSpace];
// Configure line plot style
CPTMutableLineStyle *lineStyle = [self.linePlot.dataLineStyle mutableCopy];
lineStyle.lineWidth = 2;
lineStyle.lineColor = [CPTColor blackColor];
self.linePlot.dataLineStyle = lineStyle;
CPTMutableLineStyle *symbolineStyle = [CPTMutableLineStyle lineStyle];
symbolineStyle.lineColor = [CPTColor blackColor];
CPTPlotSymbol *symbol = [CPTPlotSymbol ellipsePlotSymbol];
symbol.fill = [CPTFill fillWithColor:[CPTColor blackColor]];
symbol.lineStyle = symbolineStyle;
symbol.size = CGSizeMake(3.0f, 3.0f);
self.linePlot.plotSymbol = symbol;
// Configure graph grid line styles
CPTMutableLineStyle *gridLineStyle = [[CPTMutableLineStyle alloc] init];
gridLineStyle.lineColor = [CPTColor grayColor];
gridLineStyle.lineWidth = 0.5;
axisSet.xAxis.majorGridLineStyle = gridLineStyle;
axisSet.yAxis.majorGridLineStyle = gridLineStyle;
}
答案 0 :(得分:0)
默认情况下,轴始终在(0,0)处交叉,这远低于yRange
(9,000)的起始位置。大底部填充向上推动图形,以便y = 0是可见的,尽管图形下方有大的空白空间。您有几种选择:
使用axisConstraints
将轴锁定到某个位置(例如,绘图区域的下边缘)。
将x轴的orthogonalPosition更新为plotYMinRange
。