Math to calculate user friendly XY graph axis ticks?
Posted on 2011-04-25
Hello, this is kind of an oddball question. I'm rolling my own plot widget in .NET (I know, I know, but the UI needs for this particular plot are very application-specific) and I can plot the data just fine (this was actually surprisingly easy) but the only part I'm having trouble with (also surprising) is the calculation of the ticks to plot on the axis. All plot widgets calculate user friendly tick sizes based on two inputs
* data range (e.g., 0-10 or 0.0001 to 0.003 or 1e23 to 1e25)
* width of the plot (because of the purpose of the ticks are visual aids, you want a comfortable number of ticks in a given span of pixels)
And it will come up with good tick values (5,10,15; or 0.2, 0.4, 0.6, etc) at given locations
I'm having brain block and can't come up with the right equations to come up with user friendly tick values. And this is just esoteric enough so I can't seem to find good equations on google. This can't be too hard since every widget does it.
Does anyone have good equations, or have come across good equations in their travels?
Thanks for any help.