我有以下代码:
\begin{tikzpicture}
\begin{axis}[axis lines = left, xlabel={$x$}, ylabel={$E$}, yticklabels=\empty, xticklabels=\empty, axis lines=middle, xmax=1.2, ymax=1.2, legend pos=north west,
%symbolic x coords={-A,A},
%xmin = {-A},
%xmax = {A},
%xtickmax={2},
]
\addplot[
domain=-1:1,
samples=100, color=red,
dashed,
]
{-x^2+1};
\addlegendentry{$T(x)$}
\addplot[
domain=-1:1,
samples=100,
]
{x^2};
\addlegendentry{$U(x)$}
\end{axis}
\end{tikzpicture}
我试图强制刻度在点 (-1/sqrt(2),0) 和 (0,1/sqrt(2)) 处为 (-A,0) 和 (A,0)。有人能帮我实现这个吗?
答案1
目前还不完全清楚您的问题是否只是 xtick 标签,或者您希望重现显示的图像。假设第一种可能性:
\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xlabel={$x$}, ylabel={$E$},
ytick=\empty,
xtick = {-1,1},
xticklabels={-A,A},
extra x ticks={0},
extra x tick labels={0},
xmax=1.2, ymax=1.2,
legend pos=north west,
domain=-1:1,
samples=100,
]
\addplot[color=red,dashed] {-x^2+1};
\addlegendentry{$T(x)$}
\addplot[no marks] {x^2};
\addlegendentry{$U(x)$}
\end{axis}
\end{tikzpicture}
\end{document}