0

I would like to replicate an Arrhenius plot: it's a semi-log plot presenting something as a function of 1000/T (T being the temperature in Kelvin). This is not very convenient for the reader, so an additional axis with T is required.

I have tried using this solution and this one as well but I always end up with the secondary axis ranging from 0 to 1 instead of ~380 to 710. My guess is I haven't written properly the x coord trafo line.

Here is my MWE

\documentclass[tikz=true]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line*= bottom,
        axis y line*= left,
        ymode = log,
        xlabel={1000/T (1/K)},
        ylabel = phi,
        xmin = 1.4,
        xmax = 2.6,
        ymin = 3e-14,
        ymax = 5e-11
    ]
        \addplot[red] {9.39e-9*exp(-37.3e3/(8.314*(1000/x)))};
    \end{axis}
    \begin{axis}[
        axis x line*= top,
        axis y line*= right,
        xlabel={T (K)},
        xmin=2.6,
        xmax=1.4,
        xtick={500, 600},
        ytick=\empty,
        x coord trafo/.code=\pgfmathparse{1000/#1}
    ]
    \end{axis}
\end{tikzpicture}
\end{document}

And here is the very unsatisfying result

Top x axis ranges from 0 to 1 instead of actual temperatures around 500K

Bonus points if you can make the right-hand side ticks go away or at least correspond to the left-hand ones.

0

One way of doing this is to make use of the feature that expressions can be given to xticklabel.

For details have a look at the comments in the code. (Please note that I also did some other "improvements" to your code which might be useful.)

% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    % (use this `compat` level or higher to make use of the improved axis label positioning)
    \pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}[
    % (so we don't have to repeat ourselves we define some variables)
    /pgf/declare function={
        xmin=1.4;
        xmax=2.6;
    },
    % (moved stuff here which is used in both `axis` environments)
    every axis/.append style={
        xmin=xmin,
        xmax=xmax,
        % (restrict `domain` to the used region ...
        domain=xmin:xmax,
        %  ... and since it is a straight line we only need two `samples`)
        samples=2,
    },
]
    \begin{axis}[
        axis x line*=bottom,
        axis y line*=left,
        ymode=log,
        % (just improved the `axis` labels a bit)
        xlabel={$1000/T$ (1/K)},
        ylabel=$\varphi$,
        ymin=3e-14,
        ymax=5e-11,
    ]
        \addplot [red] {9.39e-9*exp(-37.3e3/(8.314*(1000/x)))};
    \end{axis}
    \begin{axis}[
        axis x line*=top,
        axis y line*=right,
        xlabel={$T$ (K)},
        % show the "usual" x-axis
        xticklabel={
            \pgfmathparse{1000/\tick}%
            \pgfmathprintnumber[precision=0]{\pgfmathresult}
        },
        ytick=\empty,
    ]
        % we need to add a dummy point to plot the right axis labels
        \addplot [draw=none,fill=none] coordinates {(2,0)};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

6
  • Works like a charm ! Can I still pick which ticks appear on the top axis with xticks={} ? – mackoide Jan 18 at 8:05
  • Great to hear. I think you mean xtick, right? (xticks shouldn't exist.) I don't see why not. (Did you give it a try before asking?) – Stefan Pinnow Jan 18 at 8:48
  • Sorry for the typo, it is indeed xtick={}. I tried it, by simply adding xtick={600, 500, 400}, right before ytick={} It makes the top ticks vanish and throws error "dimension too large". Changing the order of the ticks to xtick={400, 500, 600}, gives the same error. – mackoide Jan 18 at 10:37
  • That's because you need to provide the "1000/T" values, i.e. xtick={1000/400,1000/500,1000/600},. – Stefan Pinnow Jan 18 at 10:59
  • Indeed ! Thanks a lot. – mackoide Jan 18 at 14:16

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.