# Symlog scale for plotting

**URL:** <https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [May 21, 2021, 4:47pm UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021 "2021-05-21T16:47:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaofferm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jaofferm/32/21649_2.png) [@jaofferm](https://root-forum.cern.ch/u/jaofferm)\
**Post date:** [May 21, 2021, 4:47pm UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/1 "2021-05-21T16:47:24Z")

</div>

Hi ROOTers,

I was wondering if there are any plans to introduce a [“symmetric log scale” (symlog)](https://stackoverflow.com/a/3513150) in the future, as one of the axis display options for plots?

I’ve seen the topic appear in some previous talks ([2015](https://indico.cern.ch/event/443250/contributions/1098138/attachments/1149659/1649720/ROOT_Workshop_2015_Graphics.pdf), [2017](https://indico.cern.ch/event/680832/contributions/2789635/attachments/1562645/2460928/ROOT_Graphics__GUI_POW.pdf)) but as far as I can tell, this feature is not yet implemented. I’ve found that there are quite a few circumstances where it can be handy to have such an axis for a plot, e.g. one is looking at the distribution of some variable that covers many orders of magnitude and which can be either positive or negative.

My present workaround (which I’ve seen others use) is to display such histograms with the Python [matplotlib package](https://matplotlib.org), which implements this feature, but it would be great to be able to use ROOT’s own plotting abilities.

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [May 21, 2021, 11:21pm UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/2 "2021-05-21T23:21:41Z")

</div>

Thank you for bringing this up! Perhaps @axel or @couet can comment.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [May 25, 2021, 7:54am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/3 "2021-05-25T07:54:24Z")

</div>

Actually, let me invite @linev into this conversation. Sergey, do you think that’s something reasonable to do for the v7 canvas / axes?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 25, 2021, 8:03am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/4 "2021-05-25T08:03:05Z")

</div>

Such plot with ROOT 6 would require 2 log axis (along X) I guess. We can try to make some macro to implement it and see if that can be easily generalized. Do you have some data (for instance a TGraph) you would like to plot with a such scale along X ?

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [May 25, 2021, 8:04am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/5 "2021-05-25T08:04:12Z")

</div>

We could also have a dedicated axis kind for this, I suppose? Maybe internally, on the JS side, this could then be implemented the way you describe, but the user interface could be different?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 25, 2021, 8:12am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/6 "2021-05-25T08:12:37Z")

</div>

Yes in the context of JSROOT that can be a new kind of axis. For ROOT 6 I was thinking to first make a prototype with the existing TGaxis. That might work. But that will imply also transformation on the data themselves as some of them along X (for instance) will be negative. The macro prototype should take that in to account also (axis and data transformation).

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [May 25, 2021, 9:41am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/7 "2021-05-25T09:41:46Z")

</div>

Yes, we can try to implement such axis type in JSROOT.  
Need some work while d3.js does not implement such axis

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [May 25, 2021, 10:05am UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/8 "2021-05-25T10:05:01Z")

</div>

And actually there is symlog scale implemented in d3.js - see [d3-scale/symlog.js at master · d3/d3-scale · GitHub](https://github.com/d3/d3-scale/blob/master/src/symlog.js). Probably it should be not that difficult to use it

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [May 26, 2021, 1:14pm UTC](https://root-forum.cern.ch/t/symlog-scale-for-plotting/45021/9 "2021-05-26T13:14:00Z")

</div>

Here is [first try](https://jsroot.gsi.de/dev/examples.htm?more#v7_symlog) with v7 RFrame/RAxis. Same data drawn with `linear`, `log` and `symlog` X scale. While there are negative values, log scale missing some data. Only ticks selection is sub-optimal, but this is [general problem](https://github.com/d3/d3-scale/issues/162) of `d3.js` implementation. I will create PR soon.

For curiosity I add `symlog` support also for ROOT6 classes, but it only will work on the JSROOT side. [example1](https://jsroot.gsi.de/dev/examples.htm?more#th2_symlog), [example2](https://jsroot.gsi.de/dev/examples.htm?more#th2_symlog1)

 ![canvas](https://root-forum.cern.ch/uploads/default/original/3X/6/a/6ac81f2d156debd3102cc9a5a5a96739b67af1b2.png)
