在 Tikz 中用字母替换 xtick

在 Tikz 中用字母替换 xtick

我对 TikZ 环境还很陌生。我试图用希腊字母(理想情况下是\tau^{*})替换下图中的“4”。有什么想法吗?提前致谢

\begin{document}
\begin{tikzpicture}[
    declare function={
            gamma(\x)= 0.25*\x*\x*exp(-0.5*\x);
    }
]

\begin{axis}[
  no markers, domain=1: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}, 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

您可以使用

xticklabel={$\tau^{\ast}$},

完整代码:

\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=1: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}

在此处输入图片描述

xticklabels={<list>}可以为每个指定的刻度提供一个刻度标签列表xtick

\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=1: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, 6}, 
  xticklabels={$\tau^{\ast}$, $\gamma$},
  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}

在此处输入图片描述

相关内容