但是,我很难正确定义该函数,因为我的 MWE 当前是这样的:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
declare function={
gamma(\x)= 0.25*\x*\x*exp(-0.5*\x);
}
]
\begin{axis}[
no markers, domain=0:13, samples=200,
axis lines*=left, xlabel=$\tau$, ylabel=$V(\tau)$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
xtick={4},
xticklabel={$\tau^{\ast}$},
ytick=\empty,
enlargelimits=false, clip=false, axis on top,
%grid = major,
xmin=0, ymin=0,
]
\addplot [very thick,cyan] {gamma(x)};
\end{axis}
\end{tikzpicture}
\end{document}
任何帮助都将不胜感激!非常感谢!
答案1
该代码和结果主要来自 Jake 的评论(没有 CW 答案,因为没有 wiki 意图,并且我可以通过赏金将可能的要点付诸于 Jake 的精彩答案)
- 消除
clip=false
- 消除
ymin=0
- 绘制负函数:
\addplot [very thick,cyan] {-gamma(x)};
然后,对于顶部 x 轴
- 添加
axis x line = top
为轴选项
因此,您将获得:
完整代码:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
declare function={
gamma(\x)= 0.25*\x*\x*exp(-0.5*\x);
}
]
\begin{axis}[
no markers, domain=0:13, samples=200,
axis lines*=left, xlabel=$\tau$, ylabel=$V(\tau)$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
xtick={4},
xticklabel={$\tau^{\ast}$},
ytick=\empty,
enlargelimits=false,
axis x line = top,
xmin=0,
]
\addplot [very thick,cyan] {-gamma(x)};
\end{axis}
\end{tikzpicture}
\end{document}