pgf-plots zwei y-Achsen
Verfasst: Fr 27. Jul 2018, 12:03
Hallo,
ich habe folgendes Problem. Ich würde gerne in einem Diagramm zwei Datensätze plotten, welche beide von der identischen x-Achse abhängen.
Das hat auch ganz gut funktioniert, das problem ist nur, ich würde die Achsen gerne übereinander ausrichten, da es übersichtlicher ist.
D.h.: Die rechte y-Achse soll dann beginnen, wenn die linke y-Achse endet.
Hier, das was ich bereits erstellt habe:
\documentclass[paper=a4,12pt,version=last]{scrartcl}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.14}
\begin{document}
\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[label distance=2cm]
\begin{axis}[
title={Analyse},
legend pos=north west,legend style={font=\footnotesize},
width=15.5cm,height=9cm,grid=major,
xlabel=$x$,
xlabel near ticks,
ylabel= y1,
ylabel near ticks,
axis y line*=left,
symbolic x coords={0.2$\%$,0.2$\%$,0.5$\%$,1.0$\%$,1.5$\%$,2.0$\%$,2.5$\%$,3.0$\%$,4.0$\%$,5.0$\%$}, xtick=data,
x tick label style={rotate=45,anchor=east,yshift=-0.2cm}]
\addplot [color=red,mark=square*] coordinates {
(0.2$\%$, 0.08)
(0.5$\%$, 0.07)
(1.0$\%$, 0.085)
(1.5$\%$, 0.065)
(2.0$\%$, 0.07)
(2.5$\%$, 0.08)
(3.0$\%$, 0.085)
(4.0$\%$, 0.076)
(5.0$\%$, 0.068)
};
\addlegendentry{y-1-daten}
\end{axis}
\begin{axis}[legend pos=north west,legend style={font=\footnotesize}, width=15.5cm,height=9cm,grid=major,
xlabel=$x$,
xlabel near ticks,
ylabel= y2,
ylabel near ticks,
axis y line*=right,
axis x line=none,
symbolic x coords={0.2$\%$,0.2$\%$,0.5$\%$,1.0$\%$,1.5$\%$,2.0$\%$,2.5$\%$,3.0$\%$,4.0$\%$,5.0$\%$}, xtick=data,
x tick label style={rotate=45,anchor=east,yshift=-0.2cm}]
\addplot [color=blue,mark=square*] coordinates {
(0.2$\%$, 30.5)
(0.5$\%$, 30.2)
(1.0$\%$, 30.1)
(1.5$\%$, 30.05)
(2.0$\%$, 30.00)
(2.5$\%$, 30.05)
(3.0$\%$, 30.09)
(4.0$\%$, 30.08)
(5.0$\%$, 30.2)
};
\addlegendentry{y2-Daten}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
Ich freue mich über jegliche hilfe
LG
ich habe folgendes Problem. Ich würde gerne in einem Diagramm zwei Datensätze plotten, welche beide von der identischen x-Achse abhängen.
Das hat auch ganz gut funktioniert, das problem ist nur, ich würde die Achsen gerne übereinander ausrichten, da es übersichtlicher ist.
D.h.: Die rechte y-Achse soll dann beginnen, wenn die linke y-Achse endet.
Hier, das was ich bereits erstellt habe:
\documentclass[paper=a4,12pt,version=last]{scrartcl}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.14}
\begin{document}
\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[label distance=2cm]
\begin{axis}[
title={Analyse},
legend pos=north west,legend style={font=\footnotesize},
width=15.5cm,height=9cm,grid=major,
xlabel=$x$,
xlabel near ticks,
ylabel= y1,
ylabel near ticks,
axis y line*=left,
symbolic x coords={0.2$\%$,0.2$\%$,0.5$\%$,1.0$\%$,1.5$\%$,2.0$\%$,2.5$\%$,3.0$\%$,4.0$\%$,5.0$\%$}, xtick=data,
x tick label style={rotate=45,anchor=east,yshift=-0.2cm}]
\addplot [color=red,mark=square*] coordinates {
(0.2$\%$, 0.08)
(0.5$\%$, 0.07)
(1.0$\%$, 0.085)
(1.5$\%$, 0.065)
(2.0$\%$, 0.07)
(2.5$\%$, 0.08)
(3.0$\%$, 0.085)
(4.0$\%$, 0.076)
(5.0$\%$, 0.068)
};
\addlegendentry{y-1-daten}
\end{axis}
\begin{axis}[legend pos=north west,legend style={font=\footnotesize}, width=15.5cm,height=9cm,grid=major,
xlabel=$x$,
xlabel near ticks,
ylabel= y2,
ylabel near ticks,
axis y line*=right,
axis x line=none,
symbolic x coords={0.2$\%$,0.2$\%$,0.5$\%$,1.0$\%$,1.5$\%$,2.0$\%$,2.5$\%$,3.0$\%$,4.0$\%$,5.0$\%$}, xtick=data,
x tick label style={rotate=45,anchor=east,yshift=-0.2cm}]
\addplot [color=blue,mark=square*] coordinates {
(0.2$\%$, 30.5)
(0.5$\%$, 30.2)
(1.0$\%$, 30.1)
(1.5$\%$, 30.05)
(2.0$\%$, 30.00)
(2.5$\%$, 30.05)
(3.0$\%$, 30.09)
(4.0$\%$, 30.08)
(5.0$\%$, 30.2)
};
\addlegendentry{y2-Daten}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
Ich freue mich über jegliche hilfe
LG