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$.

  • $\begingroup$ 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. $\endgroup$ Feb 3, 2015 at 14:34
  • 1
    $\begingroup$ 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/… $\endgroup$ Feb 3, 2015 at 14:47
  • $\begingroup$ 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".) $\endgroup$
    – Wayne
    Feb 3, 2015 at 14:58
  • $\begingroup$ @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. $\endgroup$
    – S0rin
    Feb 3, 2015 at 15:25
  • 1
    $\begingroup$ 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. $\endgroup$
    – Nick Cox
    Feb 3, 2015 at 15:57

1 Answer 1


It's OK to make two graphs, especially when there are two different messages:

  • B is much slower than A
  • B and A have similar shapes relative to N

enter image description here

Visualization professor Alberto Cairo has written/tweeted on the subject a few times.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.