I'm trying to plot data that ranges from [-1e8,1e8] and I would like to represent it using a symmetric log plot. I've found this solution to my problem but it seems the axes fail as soon as the data is >abs(1e5). A very simple MWE even without negative data shows that the y-axis only prints up to 1.64e4 and doesn't seem to be accurate anymore at larger values:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{math}
\tikzmath
{
function symlog(\x,\a){
\yLarge = ((\x>\a) - (\x<-\a)) * (ln(max(abs(\x/\a),1)) + 1);
\ySmall = (\x >= -\a) * (\x <= \a) * \x / \a ;
return \yLarge + \ySmall ;
};
function symexp(\y,\a){
\xLarge = ((\y>1) - (\y<-1)) * \a * exp(abs(\y) - 1) ;
\xSmall = (\y>=-1) * (\y<=1) * \a * \y ;
return \xLarge + \xSmall ;
};
}
\begin{document}
\begin{tikzpicture}
\def\basis{50}
\pgfplotsset
{
y coord trafo/.code={\pgfmathparse{symlog(#1,\basis)}\pgfmathresult},
y coord inv trafo/.code={\pgfmathparse{symexp(#1,\basis)}\pgfmathresult},
yticklabel style={/pgf/number format/.cd,int detect,precision=1},
}
\pgfplotstableread{
0 1
1 1e2
2 1e3
3 1e5
4 1e7
}\dataset
\begin{axis}
[
height=.48\textwidth,
scaled ticks = base 10:0,
domain=0:4,
ytick={1e1,1e3,1e5,1e7},
x tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=3}
]
\addplot []
table [x index = {0}, y index = {1}]
\dataset;
\end{axis}
\end{tikzpicture}
\end{document}
where this is the output
Using almost the exact same code as the linked OC but extending the domain past to -5:15 causes the same problem
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{math}
\tikzmath
{
function symlog(\x,\a){
\yLarge = ((\x>\a) - (\x<-\a)) * (ln(max(abs(\x/\a),1)) + 1);
\ySmall = (\x >= -\a) * (\x <= \a) * \x / \a ;
return \yLarge + \ySmall ;
};
function symexp(\y,\a){
\xLarge = ((\y>1) - (\y<-1)) * \a * exp(abs(\y) - 1) ;
\xSmall = (\y>=-1) * (\y<=1) * \a * \y ;
return \xLarge + \xSmall ;
};
}
\begin{document}
\begin{tikzpicture}
\def\basis{1}
\pgfplotsset
{
y coord trafo/.code={\pgfmathparse{symlog(#1,\basis)}\pgfmathresult},
y coord inv trafo/.code={\pgfmathparse{symexp(#1,\basis)}\pgfmathresult},
yticklabel style={/pgf/number format/.cd,int detect,precision=2},
}
\begin{axis}
[
height=12cm,
legend pos=north west,
scaled ticks = base 10:0,
domain = -5:15,
ytick = {-100,-10, -1,0,1,10,100,1e6},
minor ytick = {-90,-80,...,-20,-9,-8,...,-2,-.9,-.8,...,.9,2,3,...,9,20,30,...,90},
tick label style = {fill=white, fill opacity=.7},
yminorgrids = true,
ymajorgrids = true,
xmajorgrids = true,
samples=200,
axis lines=center,
]
\addplot+ [mark=none] {x} ;
\addplot+ [mark=none] {exp(x)} ;
\addplot+ [mark=none] {-exp(-x)} ;
\legend {$x$,$e^x$,$-e^{-x}$}
\end{axis}
\end{tikzpicture}
\end{document}
