Visualizing the Negative Log

Introduction:

Fig1-Linear
Fig.1 Sample in Linear Scale

The logarithm of a negative value is not defined in the real space.
But in practical applications, we occasionally see that the magnitude of the data changes exponentially even in the negative area. How can we present such data in a graph? For example in Fig.1, you see the sample curve in linear scale where the curve changes exponentially in both positive and negative directions separately.

 

 

 

 

Possible Approaches:

Fig2-LogSimple
Fig. 2 Simple log scale

1) y’=Log(y) : If you simply plot the data in log scale, you obviously cannot visualize the data in the negative range as in Fig. 2. Of course, this approach is okay if data stays only within the positive region.

 

 

 

 

 

Fig3-LogAbsolute
Fig. 3 Absolute log scale

 

2) y’ = sign(y)*Log(|y|): You may first think that it’s a good idea, but when the original y value goes smaller that 1, a problem occurs – if the value is negative, the output of this function (y’) becomes positive, though when the value is positive, the output becomes negative! E.g.

sign(-0.0001)*Log(|-0.0001|) = 4
sign(0.0001)*Log(|0.0001|) = -4

See Fig. 3. We should avoid this method unless the absolute value of the data never enters less than 1.

 

 

Fig4-LogMudulas
Fig. 4 Log-Modulus transformation

3) y’ = sign(y)*log(1 + |y| ): This formula is so-called Log-Modulus transformation.  This method actually resolves the above discontinuity problem in 2), and when uphill or downhill of the original data and the converted data change synchronically. However, the biggest problem of this method is that the converted data cannot no longer depict the exponential trend as a straight line. See Fig. 4. Similar to 2), this method should be avoided unless the absolute value of the data never goes less than 1.

 

4) y’ = log(|y|) in separate positive/negative regions:

To overcome the drawbacks of above three methods,

Fig. 5 Log(|x|) scale in separate positive/ negative layers
Fig. 5 Log(|x|) scale in separate positive/ negative layers

we can separately plot negative data as log(|x|) flipped in the third/forth quadrant. To realize this approach in Origin, there are two methods to implement. One method is to set up multiple layers for negative side and positive side separately. Please see Fig. 5. Layer1 is used for positive region and layer2 is used for negative region. The range between the plus/minus minimum values around zero (in this sample, ±10E-4) is actually an infinitely wide gap with no data like an “abyss”. (The third layer was created to present only 0 data.)

 

The other method is to normalize the data

Fig. 6 Log(|x|) scale in separate positive/ negative
Fig. 6 Log(|x|) scale in separate positive/ negative regions in a single layer

by dividing by the minimum value so that the log of the minimum value shift to the zero position without changing the shape of the curve. This method can plot the data in a single layer. As you see in Fig. 6, the abyss zone of ±10E-4 is presented as a horizontal grey belt.

In either Fig. 5 or Fig. 6, you can clearly recognize visually the exponential tendencies of both the positive part and in this sample, the negative part are the same in magnitude as their slopes are visually indicated equal in the graph.

 

 

 

Sample Implementation:

To create a graph like Fig.5 or Fig. 6, I have made a sample file so that you can try by yourself. Follow the steps below to try them out:

1) Download this project file. If you unzip the file, and open it by Origin, then you find the following two folders in the Project Explorer:

– Multi-Layer presentation
– Single Layer presentation

2) You can use the empty worksheet in either folder as a template. You can enter your XY data into the first and second columns, then the necessary calculation will be proceeded automatically, and the result embedded graph will appear in the top cell in the last column. You can double-click this embedded graph to expand it, and press the Rescale button at the top right corner of the graph to adjust the scale. (You can duplicate the expanded graph window, if you want to make an independent graph.)

Fig. 7 below shows another example to demonstrates an exponentially modulated sine curve as in the left figure. The middle figure is a plot of this data visualized in multiple layers, and the right figure is the one in a single layer.

 

Fig. 7 Plots in visualized negative log scales
Fig. 7 Plots in visualized negative log scales

 

 

Note: Choosing either the multi-layer version or the single layer version, the following two criteria may help to decide: 1) In the multi-layer format, the plot line cannot be connected crossing the “abyss”, but it can do in the single layer template. 2) The multi-layer’s ticks and tick labels are of the “native” log scale, and you can customize in the Origin’s usual way. In contrast, ticks and tick labels in the single layer template are a converted presentation from the linear scale, and are not flexibly customizable.

2 Comments on “Visualizing the Negative Log”

  1. I’m confused about Hideo Fuji’s explanation of graphing negative numbers on a log scale. Your explanation of figure 6 stumps me. It seems that one or two words are missing, or a verb tense does not agree with a noun. Would you please re-write it, using more words or different words.

    1. Hi Henry Lester,
      Sorry for that typo – it seems a few words have been lost when I was editing this blog.
      Now, it reads, “Fig. 6 Log(|x|) scale in separate positive/ negative regions in a single layer“.
      It means that the data have been transformed separately in the positive part and negative part, but rendered as a single plot from one dataset in a single layer. (Observe that you see only one layer icon, [1] at the top left corner in Fig.6, in contrast to three layer icons, [1],[2], and [3] in Fig. 5.)

      –Hideo Fujii

Leave a Reply

Your email address will not be published. Required fields are marked *