13

I want to plot ONE dataset in a pgfplots and use TWO axis with different units on each axis. For example I have one dataset with temperature and want to print a °C scale on the left and a °F on the right.

quick paint example :-)

Thank you :-)

I didn't find the answer yet with google :-(

PS: This is such a great platform and it helps me so much - thanks for all the other answers on this side :-)

This is my code so far with the left axis:

\documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    xmin=0, xmax=100, %- show range
    ymin=345.95, ymax=346.17, %- show range
    domain=0:100, %- calc range
    ytick={346.16,346.11,...,340}, %- labels on the left side
    y tick label style={
      /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
      /tikz/.cd
    },      
    samples=200,
    no markers,
    enlargelimits=false,
    xlabel={x-axis},
    ylabel={Temperature T[K]},  
]
\addplot gnuplot { (346.16 - 0.002 * x)} ; 
\addplot gnuplot [style=densely dotted] { 346.16 }
node[below left] at (axis cs:100,346.16) {$73^\circ$C};   


\end{axis}\end{tikzpicture}

\end{document}
3
  • You can start from this tex.stackexchange.com/questions/53029/…
    – percusse
    Commented Jul 9, 2013 at 19:49
  • thank you "percusse" but I do not understand your hint because I do not want to add two datasets! I only want two axis for one dataset??!!...
    – Thomas
    Commented Jul 9, 2013 at 19:54
  • You don't need to have two data sets. The axes should overlap to give the two ordinate look. You can modify one of the axis without drawing anything with no x axis ticks etc. If you add a simple example with the data set people can react much faster.
    – percusse
    Commented Jul 9, 2013 at 19:56

1 Answer 1

13

Here is a simple example though I've used the Fahrenheit instead of Kelvin.

\documentclass{article}
\usepackage{pgfplots,siunitx}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
x celc
0 346.16
20 346.11
40 346.06
60 346.01
80 345.96
}\mytable


\begin{document}
\begin{tikzpicture}
    \begin{axis}[ylabel={\si{\degreeCelsius}}]
    \addplot[draw=none,no marks] table \mytable;
    \end{axis}
    \begin{axis}[
    axis y line*=right,
    ylabel={\si{\degree F}},
    yticklabel={\pgfmathparse{9*\tick/5+32}\pgfmathprintnumber[fixed,precision=2]\pgfmathresult},
    axis x line=none,
    ]
    \addplot table \mytable;
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you "percusse" for this great and simple solution :-)
    – Thomas
    Commented Jul 18, 2013 at 18:17
  • @Thomas My pleasure :)
    – percusse
    Commented Jul 18, 2013 at 18:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .