4

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.

Community
  • 1
  • 1
NichtJens
  • 1,709
  • 19
  • 27

3 Answers3

3

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.

Gian Luca Scoccia
  • 725
  • 1
  • 8
  • 26
  • Great find! I also found the reference: https://iopscience.iop.org/article/10.1088/0957-0233/24/2/027001 From the abstract it sounds like it's the original. It's not open access, though, so I currently cannot check the actual paper for that. – NichtJens Jul 08 '20 at 10:38
  • According to the paper `there is a reference on the web to 'symlog' in the Python matplotlib (2010)` so looks like symlog existed before this paper. Symlog is a sharp transition between log and linear, whereas this method seems to propose a smoother function. – Kitchi Oct 18 '22 at 11:42
1

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

enter image description here

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.

Jānis Lazovskis
  • 190
  • 2
  • 13
  • As you prefaced, this sadly doesn't answer my question, but is an extended comment. I am basically looking for where the symlog was originally invented. Since the author of the respective matplotlib code says he didn't invent it, there must be someone else! Anyway, in the last sentence, do you imply that you are looking for the code used in matplotlib to calculate the symlog? If yes, it's here: https://github.com/matplotlib/matplotlib/blob/b5d4a6c6b484afaa97ce999b36c03a28ec750ea3/lib/matplotlib/scale.py#L389 Hope that helps! – NichtJens May 10 '20 at 21:35
  • Thanks, I was looking for that. And above I was trying to say that the way `symlog` is implemented is very natural, and so asking for the "inventor" of it may be difficult and beside the point (and the notions I mentioned of reflecting and shifting are the same in your linked code, along with some finer scaling). That is, in my view the author of those lines of codes is certainly an inventor - but we can reasonably expect anyone else who is asked to implement a symmetric logarithm (and is unaware of this author's work) to come up with the same answer, and so can also be considered an inventor. – Jānis Lazovskis May 11 '20 at 08:15
  • Fair enough. It is natural, I agree, but it is not obvious. I would still think that some old math or data analysis textbook, or even the likes of Gauss, Euler, Newton etc. would have mentioned this trick. – NichtJens May 11 '20 at 08:28
0

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.

Paul Brodersen
  • 11,221
  • 21
  • 38
  • I don't really want to know whether the author of the Matplotlib implementation has seen it elsewhere before, but rather if *anyone* has seen it elsewhere before. With your logic everyone who asks a question about X should be referred to the one person that invented X, and not to anyone who knows the answer. – NichtJens Oct 12 '16 at 01:47
  • However, asking him would clearly be the most efficient way to go about it, especially as this class is quite old (2007) but he is still around. – Paul Brodersen Oct 12 '16 at 11:05
  • Yes, sure. My point was: This kind of (non-)answer would always "work". Just imagine, you had posted it verbatim to the other question about *symlog* I have linked to. – NichtJens Oct 12 '16 at 18:21
  • 1
    I went ahead and asked him. 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. I think that means my question still stands... (despite the down votes) – NichtJens Oct 13 '16 at 00:34
  • Would you mind commenting on that? I think, it at least invalidates your vote to close. I followed your suggested path to an answer, and couldn't get one there. How would you investigate it, if not on SO where the chance is high that people have seen this plotting method before? – NichtJens Oct 14 '16 at 18:09