1
votes

My goal is to create a graph similar to a picture below. I actually managed to implement it with combination of a magic numbers and set scale (0.001 - 1000). So to summarize I am looking for a formula that will calculate right position to plot lines on logarithmic y scale for range of predefined values.

Y axis: logarithmic scale

X axis: Integers

Any help will be welcome!

Logarithmic graph

1

1 Answers

0
votes

I solved it thanks to help of @DietrichEpp. Here is the function that calculates Y coordinates given:

screenY0 - min point on y axis

screenY1 - max point on y axis

dataY0 - value responding to the top of the scale

dataY1 - value responding to the bottom of the scale

func convert(data: Double, screenY0:CGFloat, screenY1:CGFloat, dataY0:Double, dataY1:CGFloat) ->CGFloat{

   return screenY0 + (log(CGFloat(data)) - log(CGFloat(dataY0))) / (log(CGFloat(dataY1)) - log(CGFloat(dataY0))) * (screenY1 - screenY0)
}