Nodeposition bei Verwendung von symbolic x coords

Tabellen und Grafiken erstellen und anordnen


MarkAnthony85
Forum-Newbie
Forum-Newbie
Beiträge: 4
Registriert: Fr 3. Feb 2017, 09:55
Wohnort: Hamburg

Nodeposition bei Verwendung von symbolic x coords

Beitrag von MarkAnthony85 »

Ich erstelle gerade ein Balkendiagramm. Dabei versuche ich eine Beschriftung ganz Links oder ganz rechts an eine Hilfslinie zubekommen. Ich habe die X-Achse anstelle von Zahlen mit Symbolen versehen damit die Balken gleichmäßig verteilt sind. Ich weiß gerade nicht wie ich die Position bei einen solchen Koordinatensystem außerhalb angeben kann.
hier das Minimalbsp. dazu:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units} 
\begin{document}
\begin{figure}\centering

\begin{tikzpicture}
    \pgfplotsset{
    legend cell align = left,
    legend pos = north east,
    symbolic x coords={14,18,21,25},
    xtick=data,
    }
\begin{axis}[
	ymajorgrids,
	no markers,
	enlargelimits=false,
	axis on top,    
	ybar=4pt,
 	width=\linewidth,
  	height=9.5cm,
  	axis lines*=left,
  	xlabel={Stickout~\lbrack mm\rbrack},
  	ylabel=$U \lbrack \mathrm{V} \rbrack$,
	axis y discontinuity=crunch,
	%xtick={14,18,21,25},
    ytickmin=30,
    ytickmax=38,
    ymin=28,
    ymax=38,
    bar width=18pt,
    enlarge x limits=0.2,
	nodes near coords,
    every node near coord/.append style=
    {
    font=\normalsize,
    fill=white,
    anchor=south
    }, 
    legend pos = north west
    ]    
    \begin{scope} % Hilfslinie
    \draw[thick,dashed,black] ({rel axis cs:1,0}|-{axis cs:14,29}) -- ({rel axis cs:0,0}|-{axis cs:25,29}) node[anchor=east,left] at (axis cs:14,29) {$U_{\mathrm{SOLL}}$};
    \end{scope}
    %\node[anchor=east] at (axis cs:14,29) {$U_{\mathrm{SOLL}}$};
    \addplot[style={fill=blue!50!cyan},error bars/.cd, y dir=both, y explicit]
    coordinates {
       	(14,32.3) += (0,1.1) -= (0,1.1)
    	(18,33.4) += (0,1.1) -= (0,1.1)
   		(21,34.3) += (0,1.1) -= (0,1.1)
        (25,35.0) += (0,1.1) -= (0,1.1)};\addlegendentry{Smart Connector}
	\addplot[style={fill=red!85!magenta},error bars/.cd, y dir=both, y explicit]
    coordinates {
       	(14,34.7) += (0,0.7) -= (0,0.7)
    	(18,35.7) += (0,0.6) -= (0,0.6)
   		(21,36.7) += (0,0.6) -= (0,0.6)
        (25,37.4) += (0,0.6) -= (0,0.6)};\addlegendentry{HKS-WeldAnalyst}
	\addplot[style={fill=green!50!olive},error bars/.cd, y dir=both, y explicit]
    coordinates {
       	(14,30.8) += (0,0.7) -= (0,0.7)
    	(18,32.1) += (0,1.5) -= (0,1.5)
   		(21,33.2) += (0,2.4) -= (0,2.4)
        (25,34.1) += (0,2.4) -= (0,2.4)};\addlegendentry{Fronius TPS 5000}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Wenn Du bei der axis Umgebung die Option
clip=false
ergänzt, dann kannst Du beispielsweise das folgende verwenden:
\node[anchor=east] at ({axis cs:14,29}-|current axis.west) {$U_{\mathrm{SOLL}}$};
Ohne die oben genannte Option kannst Du an der gewünschten Stelle eine Koordinate definieren und den Node an dieser Koordinate außerhalb der axis, aber innerhalb der tikzpicture Umgebung einfügen:
\documentclass{article} 
\usepackage[utf8]{inputenc} 
\usepackage{pgfplots}% lädt auch tikz
\pgfplotsset{compat=newest} 
\usepgfplotslibrary{units} 
\begin{document} 
\begin{figure}\centering 

\begin{tikzpicture} 
     \pgfplotsset{ 
     legend cell align = left, 
     legend pos = north east, 
     symbolic x coords={14,18,21,25}, 
     xtick=data
     } 
\begin{axis}[ 
    ymajorgrids, 
    no markers, 
    enlargelimits=false, 
    axis on top,     
    ybar=4pt, 
     width=\linewidth, 
      height=9.5cm, 
      axis lines*=left, 
      xlabel={Stickout~\lbrack mm\rbrack}, 
      ylabel=$U \lbrack \mathrm{V} \rbrack$, 
    axis y discontinuity=crunch, 
    %xtick={14,18,21,25}, 
     ytickmin=30, 
     ytickmax=38, 
     ymin=28, 
     ymax=38, 
     bar width=18pt, 
     enlarge x limits=0.2, 
    nodes near coords, 
     every node near coord/.append style= 
     { 
     font=\normalsize, 
     fill=white, 
     anchor=south 
     }, 
     legend pos = north west
     ]     
     \begin{scope} % Hilfslinie 
     \draw[thick,dashed,black] ({rel axis cs:1,0}|-{axis cs:14,29}) -- ({rel axis cs:0,0}|-{axis cs:25,29}) node[anchor=east,left] at (axis cs:14,29) {$U_{\mathrm{SOLL}}$}; 
     \end{scope}
     \coordinate (y1) at ({axis cs:14,29}-|current axis.west);
     \addplot[style={fill=blue!50!cyan},error bars/.cd, y dir=both, y explicit] 
     coordinates { 
           (14,32.3) += (0,1.1) -= (0,1.1) 
        (18,33.4) += (0,1.1) -= (0,1.1) 
          (21,34.3) += (0,1.1) -= (0,1.1) 
         (25,35.0) += (0,1.1) -= (0,1.1)};\addlegendentry{Smart Connector} 
    \addplot[style={fill=red!85!magenta},error bars/.cd, y dir=both, y explicit] 
     coordinates { 
           (14,34.7) += (0,0.7) -= (0,0.7) 
        (18,35.7) += (0,0.6) -= (0,0.6) 
          (21,36.7) += (0,0.6) -= (0,0.6) 
         (25,37.4) += (0,0.6) -= (0,0.6)};\addlegendentry{HKS-WeldAnalyst} 
    \addplot[style={fill=green!50!olive},error bars/.cd, y dir=both, y explicit] 
     coordinates { 
           (14,30.8) += (0,0.7) -= (0,0.7) 
        (18,32.1) += (0,1.5) -= (0,1.5) 
          (21,33.2) += (0,2.4) -= (0,2.4) 
         (25,34.1) += (0,2.4) -= (0,2.4)};\addlegendentry{Fronius TPS 5000} 
\end{axis}
\node[anchor=east] at (y1) {$U_{\mathrm{SOLL}}$}; 
\end{tikzpicture} 
\end{figure} 
\end{document} 
Mit ein paar weiteren Anpassungen könnte man auch die Option extra y ticks dafür nutzen.

MarkAnthony85
Forum-Newbie
Forum-Newbie
Beiträge: 4
Registriert: Fr 3. Feb 2017, 09:55
Wohnort: Hamburg

Beitrag von MarkAnthony85 »

Danke für die Antwort. Funktioniert super.

Antworten