简体   繁体   中英

What is the origin of Matplotlib's symlog (a.k.a. symmetrical log) scale?

This is not really a programming question. Rather a historical one...


I am wondering about Matplotlib's symlog or "symmetrical log" scale:

  • Is it a Matplotlib invention?
  • Has anyone seen a similar feature in another plotting tool? A math text book? Elsewhere?

For completeness, and as the documentation is a little bit on the short side:

In essence, symlog gives a linear scale below a certain threshold and a log scale above. This allows plotting a wide range of numbers (as does a log scale), including negative number and zero (which is not possible with a conventional log scale).

There are some examples here and here .


As suggested by @Paul, I went ahead and asked the original author of the Matplotlib implementation. He "didn't invent the concept" but "believe[s] it was implemented on a user request". He couldn't find a reference in the Matplotlib mailing list, though.

Can anyone point to such a reference? It might be very insightful.

While browsing the web for the same answer, I found this MatLab package that implements the same function.

In its description, the following is reported:

SYMLOG applies a modified logarithm scale to the specified or current axes that handles negative values while maintaining continuity across zero. The transformation is defined in an article from the journal Measurement Science and Technology (Webber, 2012)

I think it's reasonable to assume that is the original source of the scale.

This is more of an extended comment. To extend the logarithm continuously (or better, smoothly) over all the real numbers, it is natural to stop at a small positive value, shift, and reflect. That is, taking 1 to be small, consider the function log(x+1) for x nonnegative and -log(-x+1) for x nonpositive. I've compared this with the symlog scale below, using the demo example plots (without the linthreshy modification).

在此处输入图片说明

It's not exactly it though, as is evident in the slightly steeper first and second row left-side plots. This can be modified by moving the symmetry from x=1 and x=-1 of the logarithm closer to zero, such as x=.1 and x=-.1 . Also the region [-linthresh, linthresh] is linear, which is not the case in the right-side plots. Here is a function that produces this described approximation of matplotlib 's symlog , along with some options to toy around with.

from math import log

def symmetric_logarithm(arg,base=10,shift=1):
    if arg >= 0:
        return log(arg+shift,base)-log(shift,base)
    else:
        return -log(-arg+shift,base)+log(shift,base)

I was digging around trying to make this happen in plotly , which does not have a symlog type scale ( issue is open ), by looking for the function that is used to make it.

1) You would have to ask mdboom , who appears to have authored the relevant class (according to git blame), which is

2) SymmetricalLogScale.

Matplotlib has a github, and has been under version control for some time, so these questions are easily checked by reading the source + git blame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM