How to draw y-axis by dynamic values by using YLow and YHigh - ios

I am using core plot library for drawing the graph. I always get dynamic values for y-axis and I calculate Ymin and Ymax from the result set. The difference between (Ymax-Ymin) may be very low or very high. I want to create dynamic intervals between these values. If the difference is low major interval should be less and if it is high major interval should be high. I can't set the preferredNumberOfMajorTicks static value as values may vary. The code should work for every case. Please guide me with some code example.
#Eric Thanks for the response. I tried both of your solutions.First oneCPTAxisLabelingPolicyEqualDivisions but it always divides the range in one interval say if yMax and yMin are (128.5 and 123.2) then one interval seems nice but if values are (5550-100) then also it shows only one interval with such a big difference of values.Secondly I tried with CPTAxisLabelingPolicyFixedInterval and calculated the majorIntervalLength with by dividing the length by different number of intervals,it works fine but again I don't want to keep the value of interval static .As if I divide the length by 4 then it will always create 4 intervals even for the very low values say 4.5 and 3.5. Can you please guide me if there is any way to calculate the no of intervals by yMax and yMin?

Try the CPTAxisLabelingPolicyAutomatic axis labeling policy. That will pick "nice" intervals within the plot range for the ticks and labels. You can use the CPTAxisLabelingPolicyEqualDivisions labeling policy to always divide the plot range into equal parts, although there are no guarantees that the ticks will be on
"nice" values. If you want the most control, stick with the default labeling policy (CPTAxisLabelingPolicyFixedInterval). Divide the length of the plot range (Ymax-Ymin) by the desired number of intervals to compute the majorIntervalLength.

Related

Scaling y-axis of a histogram

I am creating a histogram of an image. I need a way to scale it in y-axis to represent it nicely, as standard image/video processing programs do. Thus I need to make stronger the small values, to make weaker the big values.
What I tried to do so far:
To scale the y-values by dividing them by the greatest y value. It allowed me to see it, but still small values are almost indistinguishable from zero.
What I have seen:
In a standard video processing tool let's say three biggest values have the same y-values on their histogram representation. However, real values are different. And the small values are amplified on the histogram.
I would be thankful for the tips/formula/algorithm.
You can create lookup table (LUT), fill it with values from a curve that describes desired behavior. Seems that you want something like gamma curve
for i in MaxValue range
LUT[i] = MaxValue(255?) * Power(i/MaxValue, gamma)
To apply it:
for every pixel
NewValue = LUT[OldValue]

IOS Core plot how to get the nearest possible value of minimum Y axis value

I am using below code to calculate the range of YAxis value:
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yLow_NBH)
length:CPTDecimalFromFloat(yHigh_NBH - yLow_NBH )];
axisSet.yAxis.preferredNumberOfMajorTicks = 4.0;
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions;
I want graph to start Y axis from best possible nearest value of Y minimum value.For example if Ymin is 5000 and intervals between two values is 500 then yAxis should start from 4500,5000,5500 and so on.
Thanks in advance
I need the graph as second image if the Ymin is 9000
First, I would stick with the default labeling policy, CPTAxisLabelingPolicyFixedInterval. You can choose the majorIntervalLength when you determine the preferred plot range and be assured the tick locations will fall at the desired values.
Take a look at how Core Plot determines tick locations with the CPTAxisLabelingPolicyAutomatic labeling policy (see this method). You can use the same algorithm to find the best tick interval and then adjust the starting location and length of the range to fall on even multiples of the tick interval. Note that Core Plot does all of the math with decimal values so it stays accurate with very large and very small values. You can use double values to simplify the code if you know your data will always fall in a range that won't cause numeric accuracy issues.

Calculating the equation of a zig zag line on a graph

I have plotted a time v/s some hardware sensor value graph. I have many readings and want to calculate a mean or any possible value (may be equation of a zig zag line, may be oscillatory motion or harmonic motion) to compare multiple readings.
I am recording data at the interval of 0.01 seconds.
Here is the graph plot of a single reading:
Here is the graph plot of multiple readings:
Also, equation of a curve can also be calculated. The data can be divided into time (2 second blocks), to calculate the equation of curve at that time.
Add each value to a buffer when you plot it, then you can calculate whatever you want.
For the mean sum the buffer contents and then divide by the number of entries in the buffer.
To find equations for curves, this page should help.

Creating a line graph with arbitrary X axis sample positions on iOS

I need to create a line graph on iOS. The graph is a time series, with time along the X axis and a percentage value along the Y axis. I need to be able to set both the X and Y position of each sample, because the samples are not taken at a regular interval (ie. the X axis positions are arbitrary). I do not want to normalise the data to a fixed interval, because that will cause rounding and so on. I have tried Core Plot and JBChartView, but I cannot find any way to set the X positions in either of these libraries.
Is there any way to set the X axis position of each sample in these libraries? I've looked through all the protocols, but it's possible I've missed something.
If it is not possible to set the X axis position in either of those libraries, can you recommend a graphing library that has this functionality?
Thanks!
Look at these Libraries
https://github.com/Boris-Em/BEMSimpleLineGraph
https://github.com/freshking/DynamicGraphView
Hopefully this will help
Core Plot can absolutely do this. The scatterplot pulls data from its datasource independently for the x- and y-values. Most of the included examples just use the data index for the x-value, but that choice was only to make the examples easier to follow. The x-values can be anything. The examples that use a date scale on the x-axis are one demonstration of this feature. The plot values do not need to be evenly spaced; the data is a series of x-y pairs.

CorePlot YAxis with two types of Scaling

Is it possible to achieve different scaling for positive part of Y-axis and different scaling for its negative part of Y-axis.The idea is to show most part of plot area for positive values and less part for negative values.
Set the yRange of the plot space so that 20% of the range is negative. For example, a range with a location of -25 and length of 125 meets this requirement.

Resources