Seite 1 von 1

pgf-plots zwei y-Achsen

Verfasst: Fr 27. Jul 2018, 12:03
von panasonic18
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

Off-Topic: Bitte beachten!

Verfasst: Fr 27. Jul 2018, 12:13
von Gast
Wie kann ich Code in meinem Beitrag hervorheben?
Nein, du sollst die Frage nicht erneut posten, sondern einfach deine Frage editieren, um das zu korrigieren.

Außerdem solltest Du \pgfplotsset{compat=1.14} nicht auskommentieren. Die compat-Einstellung sollte man immer angeben: → https://texwelt.de/wissen/fragen/19163/ ... i-pgfplots

Verfasst: Fr 27. Jul 2018, 12:16
von Gast
Und innerhalb von figure sollte man nicht center, sondern die Anweisung \centering verwenden: → https://texwelt.de/wissen/fragen/1033/w ... le-richtig

Verfasst: Fr 27. Jul 2018, 13:31
von markusv
Evtl. könntest du ein groupplot mit den entsprechenden Einstellungen verwenden.
\documentclass[ngerman]{scrartcl}
\usepackage{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}
\begin{center}
\begin{minipage}{\textwidth}
\begin{tikzpicture}
\begin{groupplot}[
xtick=data,
x tick label style={rotate=45,anchor=east,yshift=-0.2cm},
group style={
          group size=1 by 2,
          xticklabels at=edge bottom,
          vertical sep=0pt,
      },
      legend cell align=left,
      width=0.9\textwidth,
      height = 4cm,
      symbolic x coords={0.2$\%$,0.2$\%$,0.5$\%$,1.0$\%$,1.5$\%$,2.0$\%$,2.5$\%$,3.0$\%$,4.0$\%$,5.0$\%$}
]

\nextgroupplot[
        title={Analyse},
        ymin=30, ymax=30.6,
        yticklabel pos=right,
        axis x line*=top,  
        height = 4.5cm,
        legend pos=north east,
      ]
\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{y-2-daten}

\nextgroupplot[
        ymin=0.05, ymax=.1,
        height = 4.5cm,
        axis x line*=bottom,
        legend pos=south east,
      ]
\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{groupplot}
\end{tikzpicture}
\captionof{figure}{Beschriftung}
\end{minipage}
\end{center}
\end{document} 

Verfasst: Sa 28. Jul 2018, 16:31
von Bartman
@panasonic18

Ist die Ausgabe des Prozentzeichens an jedem Wert der x-Achse eine Vorgabe oder reicht es, wenn es nur einmal als Achsenbeschriftung erscheint?