代码:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{float}
\pgfplotsset{compat=1.17}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{caption}
\usetikzlibrary{shapes, arrows.meta, automata, positioning, matrix, calc}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{figure}[H]
\centering
\captionsetup{skip = 5pt}
\pgfplotsset{grid style={dashed,gray}}
\begin{tikzpicture}
\begin{semilogxaxis}[
width=12cm,
height=9cm,
xmin=10^0,xmax=10^6,
ymin=0,ymax=0.08,
xlabel = {$R_4$ ($\SI{}{\ohm}$)}, ylabel={$P_{R_4}, P_{R_5}$ ($\SI{}{\watt}$)},
xmajorgrids,
ymajorgrids,
samples=1000,
grid=both,
legend pos = outer north east] % by default
\addplot [color = blue, thick, domain = 1:10^6] {(78/(9*x + 2750))^2*x};
\addlegendentry{$P_{R_4}$};
\addplot [color = red, thick, domain = 1:10^6] {144*(x + 125)^2/(25*(9*x + 2750)^2)};
\addlegendentry{$P_{R_5}$};
\end{semilogxaxis}
\end{tikzpicture}
\caption{This plot.}
\end{figure}
\begin{figure}[H]
\centering
\captionsetup{skip = 5pt}
\begin{tikzpicture}[declare function = {r1 = 0.8;
A1 = 4*r1;
B1 = 1000*r1 - 4225;
C1 = 62500*r1;
r2 = 1.2;
A2 = 4*r2;
B2 = 1000*r2 - 4225;
C2 = 62500*r2;
R41 = (-B1 - sqrt(B1^2 - 4*A1*C1))/(2*A1);
R42 = (-B2 - sqrt(B2^2 - 4*A2*C2))/(2*A2);
R43 = (-B2 + sqrt(B2^2 - 4*A2*C2))/(2*A2);
R44 = (-B1 + sqrt(B1^2 - 4*A1*C1))/(2*A1);}]
\begin{semilogxaxis}[
width=12cm,
height=9cm,
xmin=10^0,xmax=10^6,
ymin=0,ymax=2.5,
xlabel = {$R_4$ ($\SI{}{\ohm}$)}, ylabel={$P_{R_4}/P_{R_5}$},
xmajorgrids,
ymajorgrids,
samples=1000,
grid=both]
\addplot [color = blue, thick, domain = 1:R41+1] {4225*x/(4*(x + 125)^2)};
\addplot [color = red, thick, domain = R41:R42+1] {4225*x/(4*(x + 125)^2)};
\addplot [color = blue, thick, domain = R42:R43+10] {4225*x/(4*(x + 125)^2)};
\addplot [color = red, thick, domain = R43:R44+10] {4225*x/(4*(x + 125)^2)};
\addplot [color = blue, thick, domain = R44:10^6] {4225*x/(4*(x + 125)^2)};
\end{semilogxaxis}
\end{tikzpicture}
\caption{That plot.}
\end{figure}
\end{document}
输出:
有没有办法将顶部图居中,使其 x 轴中心与底部图的中心对齐(或者更一般地说,与纸张中心的垂直线对齐)?我知道\baseline
可以这样做,但我不确定参数应该放什么。
答案1
这就是钥匙trim axis left, trim axis right
的用途。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{float}
\pgfplotsset{compat=1.17}
\usepackage{siunitx}
\usepackage{caption}
\usetikzlibrary{shapes, arrows.meta, automata, positioning, matrix, calc}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{figure}[H]
\centering
\captionsetup{skip = 5pt}
\pgfplotsset{grid style={dashed,gray}}
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{semilogxaxis}[
width=12cm,
height=9cm,
xmin=10^0,xmax=10^6,
ymin=0,ymax=0.08,
xlabel = {$R_4$ ($\SI{}{\ohm}$)}, ylabel={$P_{R_4}, P_{R_5}$ ($\SI{}{\watt}$)},
xmajorgrids,
ymajorgrids,
samples=1000,
grid=both,
legend pos = outer north east]
\addplot [color = blue, thick, domain = 1:10^6] {(78/(9*x + 2750))^2*x};
\addlegendentry{$P_{R_4}$};
\addplot [color = red, thick, domain = 1:10^6] {144*(x + 125)^2/(25*(9*x + 2750)^2)};
\addlegendentry{$P_{R_5}$};
\end{semilogxaxis}
\end{tikzpicture}
\caption{This plot.}
\end{figure}
\begin{figure}[H]
\centering
\captionsetup{skip = 5pt}
\begin{tikzpicture}[trim axis left, trim axis right,
declare function = {r1 = 0.8;
A1 = 4*r1;
B1 = 1000*r1 - 4225;
C1 = 62500*r1;
r2 = 1.2;
A2 = 4*r2;
B2 = 1000*r2 - 4225;
C2 = 62500*r2;
R41 = (-B1 - sqrt(B1^2 - 4*A1*C1))/(2*A1);
R42 = (-B2 - sqrt(B2^2 - 4*A2*C2))/(2*A2);
R43 = (-B2 + sqrt(B2^2 - 4*A2*C2))/(2*A2);
R44 = (-B1 + sqrt(B1^2 - 4*A1*C1))/(2*A1);}]
\begin{semilogxaxis}[
width=12cm,
height=9cm,
xmin=10^0,xmax=10^6,
ymin=0,ymax=2.5,
xlabel = {$R_4$ ($\SI{}{\ohm}$)}, ylabel={$P_{R_4}/P_{R_5}$},
xmajorgrids,
ymajorgrids,
samples=1000,
grid=both]
\addplot [color = blue, thick, domain = 1:R41+1] {4225*x/(4*(x + 125)^2)};
\addplot [color = red, thick, domain = R41:R42+1] {4225*x/(4*(x + 125)^2)};
\addplot [color = blue, thick, domain = R42:R43+10] {4225*x/(4*(x + 125)^2)};
\addplot [color = red, thick, domain = R43:R44+10] {4225*x/(4*(x + 125)^2)};
\addplot [color = blue, thick, domain = R44:10^6] {4225*x/(4*(x + 125)^2)};
\end{semilogxaxis}
\end{tikzpicture}
\caption{That plot.}
\end{figure}
\end{document}