![如何让 x 轴位于顶部,但线条位于底部](https://linux22.com/image/283415/%E5%A6%82%E4%BD%95%E8%AE%A9%20x%20%E8%BD%B4%E4%BD%8D%E4%BA%8E%E9%A1%B6%E9%83%A8%EF%BC%8C%E4%BD%86%E7%BA%BF%E6%9D%A1%E4%BD%8D%E4%BA%8E%E5%BA%95%E9%83%A8.png)
我有以下情节
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,ylabel=$\sin x$,
axis x line*=box]
\addplot[blue,mark=none,
domain=-10:0,samples=40]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
但我希望 x 轴位于顶部:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=6cm,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,ylabel=$\sin x$,
axis x line*=top]
\addplot[blue,mark=none,
domain=-10:0,samples=40
]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
我怎样才能让底部的线回来?
答案1
线是存在的,但它可能会与独立图像的边框混淆;border
如果您想清楚地区分它,可以赋予它一些值:
\documentclass[border = 1pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=6cm,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,ylabel=$\sin x$,
axis x line*=top]
\draw (axis description cs:0,0) -- (axis description cs:1,0);
\addplot[blue,mark=none,
domain=-10:0,samples=40
]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
该选项在四边border=1pt
添加小边框(宽);若要仅在底部和左侧添加边框,请使用。1pt
border={0pt 1pt 1pt 0pt}
答案2
您似乎只想移动刻度。这可以通过 来实现xtick pos=upper,xticklabel pos=upper
。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=6cm,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,ylabel=$\sin x$,
xtick pos=upper,xticklabel pos=upper]
\addplot[blue,mark=none,
domain=-10:0,samples=40
]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}