1

I need a pgfplot with 2 x-axis at the bottom und 2 y-axis on the left side. In my example, both x and y axes are on top of each other. How do I move these axes apart?

[![\begin{figure}\[h\]
\begin{tikzpicture}
\pgfplotsset{set layers},
\begin{axis}\[
width=0.8\textwidth,
scale only axis,
%xlabel={Watt \[\unit{\watt}\]},
%ylabel={Dezibel \[\unit{dB\m}\]},
axis y line*=left,
xmode=log,
xmin=1, xmax=10000,
ymin=0, ymax=40,
domain=1:10000,
xticklabels={\qty{1}{\mW}, \qty{10}{\mW}, \qty{100}{\mW}, \qty{1}{\watt}, \qty{10}{\watt}}, 
log ticks with fixed point, x tick label style={/pgf/number format/1000 sep=\,},
grid=both
\]
\addplot \[very thick\] {10*log10(x)};
\end{axis}
\begin{axis}\[
width=0.8\textwidth,
scale only axis,
xlabel={Watt \[\unit{\watt}\]},
ylabel={Dezibel \[\unit{dB\m}\]},
axis y line*=left,
axis x line*=none,
xmode=log,
xmin=1, xmax=10000,
ymin=-40, ymax=0,
xticklabels={\qty{100}{\nano\watt}, \qty{1}{\micro\watt}, \qty{10}{\micro\watt}, \qty{100}{\micro\watt}, \qty{1}{\mW}}, 
log ticks with fixed point, x tick label style={/pgf/number format/1000 sep=\,},
grid=both
\]
\end{axis}
\end{tikzpicture}
\caption{Leistung in Dezibelmeter \[dBm\]}
\label{fig:leistung-in-dezibelmeter}
\end{figure}][1]][1] 

Example

1
  • Does adding axis line shift=10mm to the second axis result in the output you expect? Sep 22 at 11:04

1 Answer 1

2

I am not sure whether this is what you're after, but you can use the option axis line shift to shift the axis lines away from the plot

\documentclass[border=10mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} 
\usepackage{siunitx}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=0.8\textwidth,
scale only axis,
%xlabel={Watt \[\unit{\watt}\]},
%ylabel={Dezibel \[\unit{dB\m}\]},
axis y line*=left,
xmode=log,
xmin=1, xmax=10000,
ymin=0, ymax=40,
domain=1:10000,
xticklabels={\qty{1}{\mW}, \qty{10}{\mW}, \qty{100}{\mW}, \qty{1}{\watt}, \qty{10}{\watt}}, 
log ticks with fixed point, x tick label style={/pgf/number format/1000 sep=\,},
grid=both
]
\addplot [very thick] {10*log10(x)};
\end{axis}

\begin{axis}[
width=0.8\textwidth,
scale only axis,
xlabel={Watt [\unit{\watt}]},
ylabel={Dezibel [\unit{dB\m}]},
axis y line*=left,
axis x line*=none,
xmode=log,
xmin=1, xmax=10000,
ymin=-40, ymax=0,
xticklabels={\qty{100}{\nano\watt}, \qty{1}{\micro\watt}, \qty{10}{\micro\watt}, \qty{100}{\micro\watt}, \qty{1}{\mW}}, 
log ticks with fixed point, x tick label style={/pgf/number format/1000 sep=\,},
grid=both,
axis line shift=10mm,
]
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • Thank you for the help.
    – Aaron
    Sep 22 at 12:05

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.