TransWikia.com

Re-label second x-axis on pgfplots

TeX - LaTeX Asked on February 13, 2021

I have the following simple pgfplots with multiple ordinate axes (see below for figure and MWE). I would like to plot a second x-axis at the top that is 10 times the values shown on the bottom and label it ‘x-axis 2’. How can I include this extra x-axis without an additional plot? i.e. since both axis are related, I would like to label the top x-axis.

Say if the relation was more complicated than just 10 times bottom x-axis, how can the plot be made then? Could I use an input file?

plot

MWE

documentclass[tikz]{standalone}
usepackage{pgf,pgfplots}
pgfplotsset{compat=newest}
begin{document} 

begin{tikzpicture}
pgfplotsset{set layers}
begin{axis}[scale only axis,
    xlabel={$x$},
    ylabel={Ordinate 1},
    axis y line*=left,      
    xmin=-4.0, xmax=4.0
    ]                   
    addplot[red] {x^2}; label{plot_one}
end{axis}

begin{axis}[scale only axis,
    ylabel={Ordinate 2},
    xmin=-4.0, xmax=4.0, 
    axis y line*=right,
    axis x line=none,   
    ]                       
    addlegendimage{/pgfplots/refstyle=plot_one}addlegendentry{plot 1}
    addplot[blue] {x}; label{plot_two}
    addplot[green] {3*x};  label{plot_three}
    addlegendentry{plot 2}
    addlegendentry{plot 3} 
end{axis}


end{tikzpicture}
end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP