
\label
2 つの Y 軸を区別するためにとを使用すると、ラベルの残りの部分と一緒に回転させると、\ref
で描画されたマーク\ref
が線上になくなります (以下の例を参照)。何かアイデアはありますか?
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis y line*=left, scale only axis,
ylabel={estimation 2 \ref{pgf:allsamples}}]
\addplot[blue,mark=+] table {data2.csv};
\label{pgf:allsamples}
\end{axis}
\begin{axis}[axis y line*=right, scale only axis,
ylabel={estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
\addplot[red,mark=x] table {data1.csv};
\label{pgf:swingvotes}
\end{axis}
\end{tikzpicture}
\end{document}
答え1
pgfplotsには確かにバグがあります。\ref
コマンドは「tikz画像内から呼び出された」かどうかをチェックします。しかし、このチェックは、まあ、はtikzpicture 内から呼び出されましたが、tikzpicture はノードを表示するために中断されました。
バグの結果、ラベルが予期せずずれてしまいます。
バグが修正されるまで、次の回避策を使用できます。
\documentclass{article}
\usepackage{pgfplots}
\def\fixcheck{%
\def\tikzifinpicture##1##2{##2}%
}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis y line*=left, scale only axis,
ylabel={\fixcheck estimation 2 \ref{pgf:allsamples}}]
\addplot[blue,mark=+] {x+5};
\label{pgf:allsamples}
\end{axis}
\begin{axis}[axis y line*=right, scale only axis,
ylabel={\fixcheck estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
\addplot[red,mark=x] {x};
\label{pgf:swingvotes}
\end{axis}
\end{tikzpicture}
\end{document}
すべてのラベルに、\fixcheck
チェックが「false」を返すだけのマクロを追加します。その場合、\ref
一時的な tikzpicture が追加されます。