
Ich möchte einige pgfplots
generierte Diagramme vertikal nach ihrer jeweiligen Y-Achsenbeschriftung ausrichten. Da ich dazu auch Text (oder mathematische Symbole) haben möchte, versuche ich, die TikZ-Option zu verwenden baseline=(node.position)
, aber irgendwie kann ich nicht auf den ylabel
Knoten zugreifen. Hier ist ein Mockup-Beispiel mit Diagrammen aus dempgfplots-Galerie:
\documentclass{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}[baseline=(ylabel.center)]
\begin{axis}[
height=5cm,
xlabel=Cost,
ylabel=Error]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
$\Rightarrow$
\begin{tikzpicture}[baseline=(ylabel.center)]
\begin{axis}[
height=4cm,
xmin=-3, xmax=3,
ymin=-3, ymax=3,
extra x ticks={-1,1},
extra y ticks={-2,2},
extra tick style={grid=major},
xlabel=x,
ylabel=y,
]
\draw[red] \pgfextra{
\pgfpathellipse{\pgfplotspointaxisxy{0}{0}}
{\pgfplotspointaxisdirectionxy{1}{0}}
{\pgfplotspointaxisdirectionxy{0}{2}}
};
\draw[blue] \pgfextra{
\pgfpathellipse{\pgfplotspointaxisxy{0}{0}}
{\pgfplotspointaxisdirectionxy{1}{1}}
{\pgfplotspointaxisdirectionxy{0}{2}}
};
\addplot [only marks,mark=*] coordinates { (0,0) };
\end{axis}
\end{tikzpicture}
\end{document}
Was mache ich falsch?
Antwort1
Den Y-Labels wird der Name ylabel
standardmäßig nicht zugewiesen, Sie können ihn jedoch ylabel style={name=ylabel}
in den axis
Optionen hinzufügen.
Alternativ können Sie sagen [baseline=(current axis.east)]
und nicht hinzufügen ylabel style
, was (zumindest in diesem Fall) zur gleichen Ausgabe führt.
\documentclass{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}[baseline=(ylabel.center)]
\begin{axis}[
height=5cm,
xlabel=Cost,
ylabel=Error,
ylabel style={name=ylabel}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
$\Rightarrow$
\begin{tikzpicture}[baseline=(ylabel.center)]
\begin{axis}[
height=4cm,
xmin=-3, xmax=3,
ymin=-3, ymax=3,
extra x ticks={-1,1},
extra y ticks={-2,2},
extra tick style={grid=major},
xlabel=x,
ylabel=y,
ylabel style={name=ylabel}
]
\draw[red] \pgfextra{
\pgfpathellipse{\pgfplotspointaxisxy{0}{0}}
{\pgfplotspointaxisdirectionxy{1}{0}}
{\pgfplotspointaxisdirectionxy{0}{2}}
};
\draw[blue] \pgfextra{
\pgfpathellipse{\pgfplotspointaxisxy{0}{0}}
{\pgfplotspointaxisdirectionxy{1}{1}}
{\pgfplotspointaxisdirectionxy{0}{2}}
};
\addplot [only marks,mark=*] coordinates { (0,0) };
\end{axis}
\end{tikzpicture}
\end{document}