
コードは次のとおりです。
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\tikzset{
declare function={
func(\x)= \x*\x;
}
}
\begin{tikzpicture}
\def \xmin {-3}
\def \xmax {3}
\begin{axis}[
xmin={\xmin}, xmax={\xmax},
extra y ticks={9},
extra y tick labels={$c$}]
\addplot [samples=100,domain={\xmin}:{\xmax}] {func(\x)};
\end{axis}
\end{tikzpicture}
\end{document}
を追加しましたextra y ticks={9}
が、私が本当に望んでいるのは を追加してextra y ticks={func(\xmin)}
、値が変更されたときに追加の y 目盛りラベルを適切な場所に配置できるように\xmin
することです。固定値を与えるのではなく、関数によって値を計算するコードをどのように記述すればよいでしょうかextra y ticks
? ありがとうございます!
答え1
コメントからのCW:
計算を PGF 数学マクロに設定し、マクロをextra y ticks
設定として使用します。
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\tikzset{
declare function={
func(\x)= \x*\x;
}
}
\begin{tikzpicture}
\def \xmin {-3}
\def \xmax {3}
\pgfmathsetmacro\myextratick{func(\xmin)}
\begin{axis}[
xmin={\xmin}, xmax={\xmax},
extra y ticks={\myextratick},
extra y tick labels={$c$}]
\addplot [samples=100,domain={\xmin}:{\xmax}] {func(\x)};
\end{axis}
\end{tikzpicture}
\end{document}