我需要一个 pgfplot,底部有 2 个 x 轴,左侧有 2 个 y 轴。在我的示例中,x 轴和 y 轴都位于彼此的顶部。如何将这些轴分开?
[![\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]
答案1
我不确定这是否是你想要的,但你可以使用该选项axis line shift
将轴线移离图
\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}