Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically choose between log and linear scale on graph axis

I have a web application written in Java. It has a scatterplot page, using the JFreeChart library that the user can send results to. The results are pairs of Doubles and do not belong to any specific distribution. They can be very skewed or not depending on what the user has selected to plot.

Currently the user has a drop down to select whether they want a logarithmic or linear Y-Axis. I also have a piece of code that disables the logarithmic Y-Axis option if the results contain any Doubles less than or equal to zero.

The client has submitted a feature request "Make web application automatically choose the correct type of Y-Axis (log vs linear)". Is this even possible? Does anybody know of suitable algorithms to test the results with that would suggest one axis type over the other?

like image 654
Ralph Avatar asked Mar 25 '26 14:03

Ralph


2 Answers

Using log scale is appropriate for graphs that grow exponentially.

You can check for exponential growth by plotting it in a logarithmic scale and see if it looks linear.

See Test for exponential growth.

like image 153
aioobe Avatar answered Mar 28 '26 07:03

aioobe


You could try looking at the statistics of the height differences Y_{i+1}-Y_{i} (resp. log (Y_{i+1})-log(Y_i)).

More precisely I assume you are plotting the set of pairs (X_i, Y_i) and that you have ordered them by X-coordinate : X_1 <= X_2 <= .. <=X_n. Also let Y_min and Y_max be the maximal and minimal values of Y. Of course we need Y_min >0.

Then you could compute the standard deviation of Y_{i+1}-Y_{i} divided by (Y_max - Y_min) (resp. the standard deviation of log(Y_{i+1})-log(Y_{i}) divided by (log(Y_max)-log(Y_min) ) and go for the smaller of the two.

I have never tested this but I assume this would select the scale where the curve looks the most linear, which is usually what one wants. It is also quite fast. If your datas are very noisy you may want to refine on this.

like image 33
vib Avatar answered Mar 28 '26 06:03

vib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!