# Symmetrical log plot

**URL:** https://discourse.julialang.org/t/symmetrical-log-plot/45709
**Category:** Visualization
**Created:** [August 28, 2020, 9:53pm UTC](https://discourse.julialang.org/t/symmetrical-log-plot/45709 "2020-08-28T21:53:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)
#### Post date: [August 28, 2020, 9:53pm UTC](https://discourse.julialang.org/t/symmetrical-log-plot/45709/1 "2020-08-28T21:53:41Z")

</div>

Is there anyway to do a symmetrical log plot (i.e., in both positive and negative directions), through `Plots.jl`? I know `matplotlib` has this functionality.

---

<div class="post-metadata">

### Author: ![amontoison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amontoison/32/218741_2.png) [@amontoison](https://discourse.julialang.org/u/amontoison)
#### Post date: [August 29, 2020, 2:22am UTC](https://discourse.julialang.org/t/symmetrical-log-plot/45709/3 "2020-08-29T02:22:33Z")

</div>

I didn’t find a way to do it directly with `Plots.jl`, but I implemented something for my research that could be useful for you:

```julia
 using Plots, LaTeXStrings
pgfplots()

n = 20
x = [i for i = 0:n]
y = [(-1)^i * 10^(-i/2+4) for i = 0:n]

function symlog(y, C)
  return sign.(y) .* (log10.(1 .+ abs.(y) / (10^C)))
end

function invsymlog(y, C)
  return sign.(y) .* 10^C .* (-1 .+ 10 .^ (abs.(y)))
end

C = ceil(minimum(log10.(abs.(y))))
z = symlog(y, C)

plot(x, z, lw=1, xlabel=L"k", ylabel=L"\mathcal{E}(x,y)", label="", legend=:best)
savefig("metric.tex")

open("figure.tex", "w") do io
  println(io, "\\documentclass[tikz]{standalone}")
  println(io, "\\usepackage{pgfplots}")
  println(io, "\\usepackage{tikz}")
  println(io, "\\pgfplotsset{compat=1.15}")
  println(io, "\\begin{document}")
end
run(`bash -c 'cat metric.tex >> figure.tex'`)
open("figure.tex", "a") do io
  println(io, "\\end{document}")
end

run(`pdflatex figure.tex`)

```

After that you only need to change `ytick` and `yticklabels` in the latex file.  
`yticklabels = {$-10$,$-5$,$0$,$5$,$10$}` becomes `{$-10^4$,$-10^(-1)$,$-10^(-6)$,$10^(-6)$,$10^(-1)$,$10^4$}`.  
With `C=-6` in that case, `-10` is replaced by `-10^(10+C)` and `5` is replaced by `10^(5+C)`.

Now `ytick` needs to be changed to take the value of `symlog` applied to {-10^4,-10^{-1},-10^{-6},10^{-6},10^{-1},10^4}  
which means that `ytick = {-10.0,-5.0,0.0,5.0,10.0}` becomes `ytick ={ -10.00000000004343,-5.000004342923105,-0.3010299956639813,0.3010299956639813,5.000004342923105,10.00000000004343}`.

With `sed` commands it should be possible to automate this last part of the process.  
Final figure:

 ![figure](https://global.discourse-cdn.com/julialang/original/3X/1/7/17997bdb6c909ddcb60a044399f9bcf077aee441.png)
