Seite 1 von 1

[pgfplots] 2 Y-Achsen mit Säulen Graph

Verfasst: Mo 23. Jun 2014, 21:22
von squeezie
Leider bekomme ich nach 4 Stunden probieren keinen Säulengraphen mit 2 Y-Achsen hin. Die Werte-Säulen liegen immer ganz oder halb aufeinander.
Jemand eine Lösung dazu? Ist es überhaupt möglich?
\documentclass[a4paper]{report}
\usepackage{pgfplots}%Diagramme
\begin{document}

\begin{tikzpicture}

\begin{axis}
[ybar,
scale only axis,
axis y line*=left,% the ’*’ avoids arrow heads
ylabel=Achse1]
\addplot+[fill=red]
coordinates {(1,1) (2, 2)
(3,3) };
\end{axis}


\begin{axis}
[ybar,
scale only axis,
axis y line*=right,
axis x line=none,
ylabel=Achse2]
\addplot+[fill=blue]
coordinates {(1,5) (2, 6)
(3,7) };
\end{axis}
\end{tikzpicture}
\end{document}


MFG, philipp

Verfasst: Mo 23. Jun 2014, 21:58
von esdd
Verschieb mit bar shift den einen plot nach links und den anderen nach rechts:
\documentclass[a4paper]{report} 
\usepackage{pgfplots}%Diagramme 
\pgfplotsset{compat=newest}
\begin{document} 

\begin{tikzpicture} 

\begin{axis} 
[ybar,
 bar shift=-7pt,
 scale only axis, 
 axis y line*=left,% the ’*’ avoids arrow heads 
 ylabel=Achse1] 
\addplot+[fill=red] 
 coordinates {(1,1) (2, 2) 
 (3,3) }; 
\end{axis}

\begin{axis} 
[ybar,
 bar shift=7pt,
 scale only axis, 
 axis y line*=right, 
 axis x line=none, 
 ylabel=Achse2] 
\addplot+[fill=blue] 
 coordinates {(1,5) (2, 6) 
 (3,7) }; 
\end{axis} 
\end{tikzpicture} 
\end{document}
Gruß
Elke

Verfasst: Mo 23. Jun 2014, 23:19
von squeezie
Danke, funktioniert perfekt :D