2012-04-03 19 views
2

散布図では、私のx座標データは、エポックからの時間を秒単位で表した長い数字ですが、y座標データは次のように見えます:0.675088、0.670629、0.669599。私がy軸上で大きな目盛として表示したいのは、0.64,0.65,0.66,0.67のようなものですが、現在チャートに表示されているのは0.5,0.7,1.0,1.2です。コアプロット - 散布図に非常に小さな数をプロットする

まず、上記のように(0.5〜0.7 = 0.2,0.7〜1.0 = 0.3?)不規則なティック間隔が得られるのかどうかわかりませんが、ラベル付けを試していたので推測していますCPTAxisLabelingPolicyEqualDivisionsに設定しました。誰かが、これらのラベル付けポリシーのすべてが意味するものを説明してください。

実際の質問は、私が非常に小さな数字をプロットしていると考えて、y軸上のmajorIntervalLengthにどのような値を使用する必要がありますか?現時点では私は0.01を持っていますが、この値を-nの大きさのオーダーで調整すると、実際には私のグラフに何の違いもありません。

これはPlot_Gallery_iOS DatePlot.m

-(void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme 
{ 
CGRect bounds = layerHostingView.bounds; 

NSDate *refDate = [NSDate dateWithTimeIntervalSince1970:0]; 
NSTimeInterval oneDay = 24 * 60 * 60; 

CPTGraph *graph = [[[CPTXYGraph alloc] initWithFrame:bounds] autorelease]; 
[self addGraph:graph toHostingView:layerHostingView]; 
[self applyTheme:theme toGraph:graph withDefault:[CPTTheme themeNamed:kCPTPlainWhiteTheme]]; 

[self setTitleDefaultsForGraph:graph withBounds:bounds]; 
[self setPaddingDefaultsForGraph:graph withBounds:bounds]; 

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 

NSTimeInterval now = [[NSDate date] timeIntervalSince1970]; 
NSTimeInterval threeMonthsago = now - (90*oneDay); 

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(threeMonthsago) length:CPTDecimalFromFloat(now - threeMonthsago)]; 
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.6f) length:CPTDecimalFromFloat(0.7f)]; 

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
dateFormatter.dateStyle = kCFDateFormatterShortStyle; 
CPTTimeFormatter *timeFormatter = [[[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter] autorelease]; 
timeFormatter.referenceDate = refDate; 

// Axes 
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 
CPTXYAxis *x   = axisSet.xAxis; 
x.majorIntervalLength   = CPTDecimalFromFloat(oneDay*30); 
x.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0.6f); 
x.minorTicksPerInterval  = 7; 
x.labelFormatter   = timeFormatter; 
x.labelRotation    = M_PI/4; 
x.preferredNumberOfMajorTicks = 5; 

CPTXYAxis *y = axisSet.yAxis; 
y.majorIntervalLength   = CPTDecimalFromDouble(0.001); 
y.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions; 
y.preferredNumberOfMajorTicks = 5; 
y.minorTicksPerInterval  = 10; 
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(now); 
// y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.6f) length:CPTDecimalFromFloat(0.1f)]; 
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease]; 
dataSourceLinePlot.identifier = @"Date Plot"; 

// [plotSpace scaleToFitPlots:[NSArray arrayWithObjects:dataSourceLinePlot, nil]]; 

CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease]; 
lineStyle.lineWidth    = .5f; 
lineStyle.lineColor    = [CPTColor greenColor]; 
dataSourceLinePlot.dataLineStyle = lineStyle; 

// Auto scale the plot space to fit the plot data 
// Extend the ranges by 30% for neatness 
[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:dataSourceLinePlot, nil]]; 
CPTMutablePlotRange *xRange = [[plotSpace.xRange mutableCopy] autorelease]; 
CPTMutablePlotRange *yRange = [[plotSpace.yRange mutableCopy] autorelease]; 
[xRange expandRangeByFactor:CPTDecimalFromDouble(1.3)]; 
[yRange expandRangeByFactor:CPTDecimalFromDouble(1.3)]; 
plotSpace.xRange = xRange; 
plotSpace.yRange = yRange; 

dataSourceLinePlot.dataSource = self; 
[graph addPlot:dataSourceLinePlot]; 
} 

に基づいて私のコードのスニペットUPDATEです:

はこれを行うことによって、カスタムyの大目盛を設定することで、問題を解決:

y.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided; 

NSSet *majorTickLoc = [NSSet setWithObjects:[NSDecimalNumber numberWithFloat:0.64f], [NSDecimalNumber numberWithFloat:0.65f], [NSDecimalNumber numberWithFloat:0.66f], [NSDecimalNumber numberWithFloat:0.67f],[NSDecimalNumber numberWithFloat:0.68f],nil]; 
y.majorTickLocations = majorTickLoc; 

しかし、数字はまだ丸みを帯びているように見えました。つまり、0.6、0.7、0.7などの小数点以下の桁が1つしかないことがわかりました。ラベルに数値フォーマッタを設定すると動作します:y軸用labelFormatterを設定

y.majorIntervalLength = CPTDecimalFromString(@"0.1") 

答えて

0

は、この次のコードを試してみてください。

NSNumberFormatter *newFormatter = [[[NSNumberFormatter alloc] init] autorelease]; 
newFormatter.minimumIntegerDigits = 1; 
newFormatter.maximumFractionDigits = 2; 
newFormatter.minimumFractionDigits = 2; 
y.labelFormatter = newFormatter; 
+0

これが私の質問に答えるかどうかわかりません。私は、yのメジャーダニとして次の数値を望む:0.64,0.65,0.66,0.67それを達成する方法は分からない。 – user1187378

+0

今私はこのコードを更新answer.tryです...! – Dinesh

0

NSNumberFormatter *yFormatter = [[NSNumberFormatter alloc] init]; 
[yFormatter setMinimumFractionDigits:4]; 
[yFormatter setMaximumFractionDigits:4]; 
[yFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; 
y.labelFormatter = yFormatter;