1

I would to plot a data series with a focus on the behavior at zero crossing. Logarithmic x-y-scaling cannot be applied because of there are negative y-values. I tried scaling to scale the y-axis with a hyperbolic sine through a coordinate. Somehow, the sample code does not plot data with negative values, although the inverse hyperbolic sine should also defined for negative real numbers.

    \documentclass{standalone}
    \usepackage{filecontents}
    \begin{filecontents*}{\jobname.dat}
        x, y
        0.000, -11.593
        1000.000, 394200.483
        0.029, -11.595
        500.015, 191387.137
        0.060, -11.598
        250.037, 89886.332
        0.092, -11.601
        125.065, 38883.652
        0.129, -11.604
        62.597, 12269.691
        0.188, -11.610
        31.393, 731.387
        0.676, -11.679
        16.034, -15.857
        23.713, -17.985
        27.553, -19.100
        29.473, 292.001
        27.671, -19.121
        28.572, 88.339 
        27.831, -19.150
        28.201, 5.087  
        28.124, -12.353
        28.178, -0.001
        28.179, 0.111
    \end{filecontents*}
    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \begin{document}
    \begin{tikzpicture}
    \pgfplotsset{
        y coord trafo/.code={\pgfmathparse{ln(#1 + sqrt( #1^2 + 1))}\pgfmathresult},
        y coord inv trafo/.code={\pgfmathparse{#1}\pgfmathresult},
     }
    \begin{axis}[
    %   xmode=log,
        grid=major,
        xmin=0,
        xmax=1000,
        ymin=0]
        \addplot+[only marks] table[col sep=comma,x=x,y=y] {\jobname.dat};
    \end{axis}
    \end{tikzpicture}
    \end{document}

Side question: How can I make to y-labels be the actual function values and their scaled ones? My idea is to use something like yticks={ln(1), ln(10+sqrt(10^2+1), ...} and `yticklabels={1,10,...}'.

1

As far as I know, y coord inv trafo is not applied to coordinates, but to tick positions. So in order to get a different scaling for negative coordinates you can use pgfmaths ifthenelse. Additionally in some places #1 must be put in (), if negative tick coordinates are given manually with ytick.

For the yticks itself, if you want to use some math expression you have to put them in () too. But you don't realy need this here, because the given coordinates are also transformed with y coord trafo.

Caution, there will be dimension too large errors for values greater than 127 with your equations, because 128^2 will exceed the maximum of 16383.99999.

\documentclass[border=2mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.dat}
    x, y
    0.000, -11.593
    1000.000, 394200.483
    0.029, -11.595
    500.015, 191387.137
    0.060, -11.598
    250.037, 89886.332
    0.092, -11.601
    125.065, 38883.652
    0.129, -11.604
    62.597, 12269.691
    0.188, -11.610
    31.393, 731.387
    0.676, -11.679
    16.034, -15.857
    23.713, -17.985
    27.553, -19.100
    29.473, 292.001
    27.671, -19.121
    28.572, 88.339 
    27.831, -19.150
    28.201, 5.087  
    28.124, -12.353
    28.178, -0.001
    28.179, 0.111
\end{filecontents*}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
    y coord trafo/.code={\pgfmathparse{ifthenelse(#1<0,#1,ln((#1) + sqrt((#1)^2 + 1)))}},
 }
\begin{axis}[
%   xmode=log,
    grid=major,
    xmin=0,
    xmax=1000,
% remove to get negative y coordinates
%    ymin=0,
% works with '()' around coordinates
%    ytick={(ln(1)),(ln(10+sqrt(10^2+1)))},
%    yticklabels={1,10},
% needs '()' around '#1' in y coord trafo for negative numbers
    ytick={-20,-10,0,10,100},
    yticklabels={-20,-10,0,10,100},
    ]
    \addplot+[only marks] table[col sep=comma,x=x,y=y] {\jobname.dat};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.