Stacked Bar mit Zusatzlinien

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: Stacked Bar mit Zusatzlinien

von esdd » Mo 29. Mai 2017, 12:52

Vielleicht geht das auch irgendwie eleganter, aber hier ist zumindest mal ein Vorschlag:
\documentclass[tikz]{standalone} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.10} 
\begin{document} 
\begin{tikzpicture}
  \begin{axis}[ 
      ybar stacked, 
      bar width=15pt, 
      nodes near coords, 
      enlargelimits=0.15, 
      legend style={at={(0.5,-0.20)}, 
        anchor=north,legend columns=-1}, 
      symbolic x coords={tool1, tool2}, 
      xtick=data, 
      x tick label style={rotate=45,anchor=east},
      ymajorgrids,
      /tikz/mstyle/.style={draw,red,very thick,text=black},
      /tikz/mleft/.style={xshift={-(.5*\pgfplotbarwidth+2.5pt)}},
      /tikz/mline/.style={insert path={--+({\pgfplotbarwidth+5pt},0pt)}},
    ]
    \path[mstyle]([mleft]axis cs:tool1,2)[mline]node[right]{$2$};
    \path[mstyle]([mleft]axis cs:tool2,3)[mline]node[right]{$3$};
    
    \addplot plot coordinates {(tool1,0) (tool2,2)}; 
    \addplot plot coordinates {(tool1,0) (tool2,0)}; 
    \addplot plot coordinates {(tool1,6) (tool2,6)}; 
    \addplot plot coordinates {(tool1,4) (tool2,2)};

  \end{axis} 
\end{tikzpicture} 
\end{document}
Bild

Beachte, dass Du beim Zeichnen der Striche die symbolischen x-Koordinaten verwenden musst. Ist es Absicht, dass Du Kompatibilität zu der recht alten Version 1.10 herstellst? Aktuell ist derzeit 1.14
Dateianhänge
gl_stackedplotmark.png
gl_stackedplotmark.png (9.91 KiB) 1254 mal betrachtet

Stacked Bar mit Zusatzlinien

von tekken01 » Sa 27. Mai 2017, 22:17

Sehr verehrtes Forum,

wie kann ich zusätzliche Striche in meinem Balkendiagram einzeichnen ? Ich hätte es gerne genauso wie hier:

Bild

ich dachte dass es möglicherweise über den draw Befehl ginge... :? Gibt es dazu eine elegante Lösung ?

hier mein minimalbeispiel:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=15pt,
nodes near coords,
enlargelimits=0.15,
legend style={at={(0.5,-0.20)},
	anchor=north,legend columns=-1},
symbolic x coords={tool1, tool2},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
%\draw[red, very thick] (axis cs:0.7-\,2) -- (axis cs:1.3+\,2);

\addplot+[ybar] plot coordinates {(tool1,0) (tool2,2) 	};
\addplot+[ybar] plot coordinates {(tool1,0) (tool2,0) 
	};
\addplot+[ybar] plot coordinates {(tool1,6) (tool2,6)	};
\addplot+[ybar] plot coordinates {(tool1,4) (tool2,2)};
\end{axis}
\end{tikzpicture}
\end{document}

Nach oben