# Scaling the x-Axis in a more logarithmic way

While I have found some answers for equidistant scaling, I did not find an answer which I was able to transfer directly to my problem. I have one interval going from 10^-8 to 3*10^-8 , one from 3*10^-8 to 8*10^-6 and one from 8*10^-6 to 0.25. It would be great if all areas would of roughly the same same size. Any help is highly appreciated. (Thanks marmot for your help up to this point.) I think the correct commands are already there with \xbarrier and xcoord trafo, but I honestly have no clue how to use them corrctly, even after reading the manual.

          \documentclass[letter,12pt,twoside]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{mathptmx}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[
labelnode/.style={font=\footnotesize, above},
labelline/.style={stealth-stealth,shorten >=0.1pt, shorten <=0.5pt}
]
\def\xBarrier{10}
\begin{axis}[
axis lines = left,
xlabel = $\beta$,
ylabel = {$E[\pi_B^D]$},
width=16cm,
height=6cm   ]
x coord trafo/.code={%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{#1 < \xBarrier ? #1 : (\xBarrier - ln(\xBarrier) +ln(#1))}},
xtick={log10(#1^9),log10(#1^8),log10(#1^7),log10(#1^5),1e(-5),1e(-2),0.2},
xticklabel={%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{\tick < \xBarrier ? \tick :
(\tick + ln(10)-10)/ln(10)
}%
\ifpgfmathfloatcomparison
\pgfmathprintnumber\tick
\else
$10^{\pgfmathprintnumber\pgfmathresult}$%
\fi
\pgfkeys{/pgf/fpu=false}%
}]
\addplot [
domain=1.*10^(-8) : 3.04985*10^(-8),
samples=100,
color=red     ] {10-4.16667 + 5* 2^(8/9)* (1/x)^(1/9)} ;

\addplot [
domain=3.04985*10^(-8) : 8.24002*10^(-6),
samples=100,
color=red     ] {10 + (10 * (1/x)^(1/9))/3^(1/9)};

\addplot [
domain=8.24002*10^(-6) : 0.25,
samples=100,
color=red   ] {10+ 2.5 + 5 * 2^(7/9)* (1/x)^(1/9)};
\coordinate (l) at (rel axis cs:0,1);
\end{axis}
\end{tikzpicture}
\end{document}


Thank you so much in advance.

• The whole x-Axis should go from 10^-9 to 0.25 and the scaling should be such that the three functions defined in the threee intervals you mentioned can be distinguished. That means that the scale of the x-Axis must be somewhat logarithmic I think. Is this now clear? Thanks that you are willing to help me – user34047 Nov 22 '18 at 18:06
• Of course i did :-D I have not even seen the error when you pointed it to me. Yeah the way you said it , is what I meant. – user34047 Nov 22 '18 at 18:47
• Hi marmot, the answer you linked looks very promising. I read the manual and tried to adapt my code, nut the pgfmathparse is too much for me :-( Perhaps you can have another quick look at my mess. Thank you so much – user34047 Nov 23 '18 at 9:04
• I think from my current changes only the \xbarrier thing and pgfmathparse need to be changed. But I have no clue how, even with your tips – user34047 Nov 23 '18 at 9:23
• What is sth. ? – hpekristiansen Nov 23 '18 at 18:35

## 1 Answer

As I mentioned in my comment, I think choosing a single continuous coordinate transformation might be a better choice. As you can see here,

\documentclass[letter,12pt,twoside]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}[
labelnode/.style={font=\footnotesize, above},
labelline/.style={stealth-stealth,shorten >=0.1pt, shorten <=0.5pt}
]
\begin{axis}[
axis lines = left,
xlabel = $\beta$,
ylabel = {$E[\pi_B^D]$},
width=16cm,
height=6cm,
x coord trafo/.code={%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{sign(log10(#1))*pow(abs(log10(#1)),5/3)}
},
x inverse coord trafo/.code={%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{10^(-pow(abs(#1),3/5))}
},
xtick={1.18*10^(-9),5*10^(-8),1*10^(-8),1*10^(-7),1*10^(-5),1*10^(-2),0.2},
xticklabel={%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{10^(-pow(abs(\tick),3/5))}%
$\pgfmathprintnumber\pgfmathresult$%
\pgfkeys{/pgf/fpu=false}%
},
]
\addplot [
domain=1.18*10^(-9) : 3.04985*10^(-8),
samples=100,
color=red     ] {100-4.16667 + 5* 2^(8/9)* (1/x)^(1/9)} ;

\addplot [
domain=3.04985*10^(-8) : 8.24002*10^(-6),
samples=100,
color=red     ] {100 + (10 * (1/x)^(1/9))/3^(1/9)};

\addplot [
domain=8.24002*10^(-6) : 0.25,
samples=100,
color=red   ] {100+ 2.5 + 5 * 2^(7/9)* (1/x)^(1/9)};

\coordinate (l) at (rel axis cs:0,1);

\path (1.8*10^-9, 0 |- l) coordinate (aux1)
(3.04985*10^-8, 0 |- l)  coordinate (aux2)
(8.24002*10^-6, 0 |- l) coordinate (aux3)
(0.25, 0 |- l) coordinate (aux4);

\draw[dashed] (3.04985*10^-8, 100) -- (3.04985*10^-8,200);
\draw[dashed] (8.24002*10^-6, 100) -- (8.24002*10^-6,200);
\end{axis}
\draw [labelline] (aux1) -- node[labelnode]{$n^D=2$} (aux2);
\draw [labelline] (aux2) -- node[labelnode]{$n^D=3$} (aux3);
\draw [labelline] (aux3) -- node[labelnode]{$n^D=4$} (aux4);

\end{tikzpicture}
\end{document} the three intervals are mapped to intervals of comparable length. This plot seems also to reveal that the plot is not exactly continuous, but I do not have the background information that allows me to judge whether or not this is an issue, or some numerical instability.

Note that I was able to kick out everything out of your preamble but \usepackage{pgfplots} (and I added \pgfplotsset{compat=1.16}).

• Thank you so much. I only had to do some minor editing and then it looked more than awesome. Great work by you! – user34047 Nov 26 '18 at 8:56