我正在制作一个图,我想在x
- 轴的位置出现一个勾号c/(1 + c)
,其中c
是一个常数,我希望能够改变它。我不知道该怎么做。我试过使用\usetikzlibrary{calc}
,但到目前为止还没有成功。
平均能量损失
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\newcommand{\constant}{0.4}
\begin{document}%
\begin{tikzpicture}%
\begin{axis}[%
xmin = 0,
xmax = 1,
xtick = {0,\constant}, % replace 0 by \constant/(1 + \constant)
ymin = 0,
ymax = 1
]%
\addplot[domain = 0:1] {\constant/(\constant + x)};
\end{axis}%
\end{tikzpicture}%
\end{document}%
答案1
例如:
\documentclass[tikz, border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\newcommand{\constant}{0.4}
\usepackage{xintexpr}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0,
xmax = 1,
xtick =
{\xinttheiexpr[2]\constant/(1+\constant)\relax,\constant}, % replace 0 by \constant/(1 + \constant)
% with 2 digits after decimal mark of precision which seems anyhow to be
% the format kept par tikz here
ymin = 0,
ymax = 1
]
\addplot[domain = 0:1] {\constant/(\constant + x)};
\end{axis}
\end{tikzpicture}
\end{document}