# How to plot data when their values differ by orders of magnitude?

What is the best practice for plotting data where their values differ by several orders of magnitude?

For example, suppose that you are comparing the learning times of two machine learning algorithms $A$ and $B$ and you have the following data:

n y_A   y_B
1 0.00001 0.02
2 0.00002 0.04
3 0.00003 0.08
4 0.00002 0.04
5 0.00001 0.02


Here $n$ is the number of features, and $y$ is the learning times. The plot of these results looks like this: However, the plot suggests like algorithm A has 0 learning time, or constant time. Therefore, should I use a semi-log plot? What is the best practice in this scenario? The point of the plot is to show that algorithm $A$ learns substantially quicker than algorithm $B$ for all values of $n$.

• Typically, you'd first look at transforming the relevant variables, using logs as you did, or possibly some other Box-Cox-transformation (of which the log is one special case). It's hard to give general guidance here. Feb 3, 2015 at 14:34
• Here are a few ideas: earlh.com/blog/2009/07/20/… and r-bloggers.com/multiple-y-axis-in-a-r-plot and earlh.com/blog/2009/07/20/… Feb 3, 2015 at 14:47
• Typically I'd expect that you're worried about how an algorithm scales as $n$ becomes very large, in which case a log-log plot might be useful. (As an aside, it's weird that run times go up and then down as a function of "input size".) Feb 3, 2015 at 14:58
• @Wayne this is just a toy example. However, in my actual data the x axis represents the number of features of a machine learning algorithm. Feb 3, 2015 at 15:25
• Here and elsewhere the fact that you got similar shapes and sizes for the curves on a transformed scale is a sign of a useful transformation (even if the data are made up here to ensure that!). A useful tip for transforming times is that their reciprocals are speeds. Feb 3, 2015 at 15:57 