Core Plot: How to set xRange/yRange with different scales? - iphone

I am wanting to use Altitude for my Y range and Distance for my X range. Currently this is what I am using:
plotSpace.xRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(0.0)
length:CPDecimalFromUnsignedInteger(sortedArray.count)];
plotSpace.yRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(min)
length:CPDecimalFromFloat((max - min))];
That doesn't set the X range correctly, because it just sets it to the number of points in the array, which is about 2500. I have tried setting the xRange to to the max value in my distance array, but that really screws up the graph.
How can I have two different scales for x and y and still have the graph be correct?
Here is what it looks like when I change the xRange to be my distance, the graph goes flat:

Calculate your min and max distance and use those to set the xRange and calculate your min and max altitude and use those to set the yRange.

Related

OxyPlot: Display labels for max/min values on LinearColorAxis

I'm trying to display labels for maximum and minimum values on color axis.
I've created and LinearColorAxis object, set max and min values from result array.
Currenty max = 180, min = -180
var colorAxis = new LinearColorAxis();
colorAxis.Palette = result.GetPalette();
colorAxis.Position = AxisPosition.Right;
colorAxis.Maximum = result.Array.Max2D();
colorAxis.Minimum = result.Array.Min2D();
After that I can see the next graph:
Graph
But as you can see there are no labels for min and max values. How can I do that? And need to display label for it to see my 180 and -180 values. Step for axis can be changed when I have other result with other min and max values. But I should display labels of min/max values for all cases.

Recalculate values on different scale in chart

I want to display some values inside a chart-like tool based on pixels.
Problem is that the left xAxis has a max scale of 200 pixel. Inside that pixel square i want to display different altitude values that can range from 200m-1500m or 324m-724m or anything else.
So i need to recalculate the orignal values by a factor to display them inside this chart. Haven't find the right solution yet. Any hints ?
You have range of Y-coordinates 0..YMax (200 for your case) and data range Data_Low..Data_High (find min and max values).
To map data range to axis range, use linear formula:
Y = (Value - Data_Low) * YMax / (Data_High - Data_Low)
If axis starts from YMin, use
Y = YMin + (Value - Data_Low) * (YMax - YMin) / (Data_High - Data_Low)

Dynamically update the ylimits to fit data for horizontal-only zoom

Lets consider a simple example of a plot
y_axis = [randi([0,20],1,100) randi([20,40],1,100) randi([0,20],1,100)];
x_axis = 1:300;
ax = subplot(1,1,1)
plot(x_axis,y_axis);
get(gca,'ylim')
zoom on
setAxesZoomMotion(zoom,ax,'horizontal');
axis tight
Here the y-axis limit depends on the area I zoom in for example in the middle the minimum value of y is 20 but on the sides of the plot it is 0 , I have limited the zoom to the x axis only , now what i want is when i zoom in for example in the middle the y-axis limits resets itself to the minimum and maximum value of y axis currently visible. I have tried setting the axis to 'tight' and 'auto', is there any property or function which in MATLAB which does that ?
You could use the zoom object and set the ActionPostCallback to a function which will call axis auto y to automatically re-calculate the ylimits to fit the visible data.
y_axis = [randi([0,20],1,100) randi([20,40],1,100) randi([0,20],1,100)];
x_axis = 1:300;
ax = subplot(1,1,1)
hplot = plot(x_axis,y_axis);
hzoom = zoom(ax);
hzoom.Motion = 'horizontal';
hzoom.ActionPostCallback = #(fig,e)axis(e.Axes, 'auto y');

How to define end of x and y axis in core plot for ipad application

I am working on graph for an iPad application, I am able to plot the graph perfectly but I cannot figure out how to end the y or x axis after the max and min value on either axes. Right now, I can only play around with the axis labels (remove, hide, change value) but straight line remains there.
Im assuming that you don't have data going past where you wan't your axis to stop.
So the easiest way to is to decrease the size of your CPTGraphHostingView so your graphs go to the edge, or set the padding values for your graph:
CGFloat BoundsPadding = 10.0;
graph.paddingLeft = boundsPadding;
graph.paddingRight = boundsPadding;
graph.paddingTop = boundsPadding;
graph.paddingBottom = boundsPadding;
or set padding on your plotAreaFrame:
graph.plotAreaFrame.paddingLeft = 10;

How to plot nagative values on graph in core plot?

I am able to draw lines with positive decimal values but in case of negative values my graph shows nothing neither on axis nor on graph.
How do I do it?
You should simply need to set the plot ranges to encompass the negative values you wish to display. For example:
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)lineChart.defaultPlotSpace;
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-10.0f) length:CPDecimalFromFloat(20.0f)];
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-10.0f) length:CPDecimalFromFloat(20.0f)];
will show values from -10 to 10 in X and Y.