pgfplots: セカンダリ Y 軸目盛りラベルをプライマリ Y 軸ラベルの機能として機能させるにはどうすればよいですか?

pgfplots: セカンダリ Y 軸目盛りラベルをプライマリ Y 軸ラベルの機能として機能させるにはどうすればよいですか?

ここでは、セカンダリ Y 軸目盛りラベルを追加し、手動で指定するのではなく、プライマリ Y 軸目盛りラベルの機能として使用したいと思います。

たとえば、次の疑似関数に従うにはセカンダリ ラベルが必要です。

secondary y tick label = primary y tick label * 100

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}

\begin{axis}[
xmin=0,xmax=10,
xtick={0,2,...,10},
xticklabels={
    ,
    x1,
    x2,
    x3,
    x4,
    }
]
\addplot+[
only marks,
error bars/.cd,
y dir=both,
y explicit,
]
table
[
y error plus=ey+,
y error minus=ey-,
]{  
    x       y       ey+     ey-
    2       0       .5      1
    4       0       0       0.5
    6       0       1       0
    8       0       0.5     0.5
};

\end{axis} 
\end{tikzpicture}

\end{document}

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

答え1

グラフに 2 番目の y 軸が必要な場合は、既存の y 軸のみの軸の上に別の軸を追加できます。したがって、最初の軸には x と y1 が含まれ、2 番目の軸には y2 のみが含まれます。詳細については、pgfplots マニュアルの 4.9 章を参照してください。

おそらくこれを実現するにはもっと良い方法があるでしょうが、これは私が最初に思いついた方法であることに注意してください。

編集:

2 番目の軸ラベルを最初の軸ラベルの数学的関数として使用する場合、2 つの変数 varymax と varymin を使用するのはどうでしょうか。そうすれば、それらの値を関数として指定できるため、手動で行う必要がなくなります。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}

\newcommand{\varymin}{-1.2} 
\newcommand{\varymax}{1.2}

\begin{axis}[
xmin=0,xmax=10,
ymin=\varymin,ymax=\varymax,
xtick={0,2,...,10},
xticklabels={
    ,
    x1,
    x2,
    x3,
    x4,
    }
]
\addplot+[
only marks,
error bars/.cd,
y dir=both,
y explicit,
]
table
[
y error plus=ey+,
y error minus=ey-,
]{  
    x       y       ey+     ey-
    2       0       .5      1
    4       0       0       0.5
    6       0       1       0
    8       0       0.5     0.5
};

\end{axis} 
\begin{axis}[
xmin=0,xmax=10,
ymin=\varymin*100,ymax=\varymax*100,
axis y line*=right,
axis x line=none,
ylabel=Second label]
\end{axis}
\end{tikzpicture}

\end{document}

結果は次のとおりです。

結果

関連情報