固定値を与える代わりに関数で「追加の y ティック」値を計算する方法

固定値を与える代わりに関数で「追加の y ティック」値を計算する方法

コードは次のとおりです。

\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}

ここに画像の説明を入力してください

関連情報