我希望 x 刻度线与 x 轴对齐。但目前,刻度线与 x 轴重叠。我在网上找到的所有示例都没有指定 x 标签的位置,但它们对齐正确。
我还想知道如何将 y 轴的标签( <i(t)> )放在 y 轴的顶部。
提前致谢。
这是我目前的代码:
\begin{center}
\resizebox{10cm}{!}{
\begin{tikzpicture}
\begin{axis}[
grid=major,
xtick align = center,
xlabel={$t$},
ylabel={$<i(t)>$},
xmin=0,
xmax=3,
xtick={1,2,3},
ymin=0,
ymax=20,
ytick={0,5,10,15,20}
]
\addplot[thick,samples=400] {((1-2)*(x/1-1))^(1/(1-2))};
\node at (axis cs:0.6,18) {$\kappa = 2$};
\addplot[thick,samples=400] {((1-0.5)*(x/1+2))^(1/(1-0.5))};
\node at (axis cs:2.6,7) {$\kappa = 0.5$};
\addplot[thick,samples=400] {(exp(x/1+0))};
\node at (axis cs:2.6,18) {$\kappa = 1$};
\end{axis}
\end{tikzpicture}}
\end{center}
答案1
xlabel
ylabel
默认是居中的,你可以通过设置 来控制 的定位y label style={at={(axis description cs:0,1.05)},...}
。同样, 也xlabel
可以根据需要进行修改。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{center}
\resizebox{10cm}{!}{
\begin{tikzpicture}
\begin{axis}[
grid=major,
xtick align = center,
y label style={at={(axis description cs:0,1.05)},rotate=-90,anchor=south},
xlabel={$t$},
ylabel={$<i(t)>$},
xmin=0,
xmax=3,
xtick={1,2,3},
ymin=0,
ymax=20,
ytick={0,5,10,15,20}
]
\addplot[thick,samples=400] {((1-2)*(x/1-1))^(1/(1-2))};
\node at (axis cs:0.6,18) {$\kappa = 2$};
\addplot[thick,samples=400] {((1-0.5)*(x/1+2))^(1/(1-0.5))};
\node at (axis cs:2.6,7) {$\kappa = 0.5$};
\addplot[thick,samples=400] {(exp(x/1+0))};
\node at (axis cs:2.6,18) {$\kappa = 1$};
\end{axis}
\end{tikzpicture}
}
\end{center}
\end{document}