Y Achse bei Diagramm zentriert

Tabellen und Grafiken erstellen und anordnen


Siemo
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Di 9. Feb 2016, 08:54

Y Achse bei Diagramm zentriert

Beitrag von Siemo »

Hallo,

ich bin begeisterter User von diesem Forum, bist jetzt konnten alle meine Probleme von mir durch suchen gelöst werden.

Bei diesem muss ich mich anmelden und hoffe auf einen schnelle Lösung. In dem Manual "PGFPLOT" habe ich auch nicht gefunden oder übersehen.

Nun zum meinem Problem:

Bei meinem Diagramm, möchte ich gerne die Y-Achse in der Mitte des Diagramms ohne Beschriftung platzieren.

Minimalbeispiel:


\documentclass[12pt,a4paper,oneside,
			BCOR=5mm,
			%numbers=noenddot,
			]
			{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx}		%Bilder einfügen
\usepackage{xcolor}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween} 
\usetikzlibrary{intersections}


\begin{document}
\begin{figure}[htbp]
\centering
 \begin{tikzpicture}[scale=1]
  \begin{axis}[hide y axis,
               axis x line = bottom,
               ytick=\empty,
               x post scale = 2.25,
               y post scale = 1.25,
               xmin=-3.5,xmax=3.5,
               xtick={-3,-2,-1,0,1,2,3},
               xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$},
               ]
   \addplot+[samples = 50,
            domain = -3.5:3.5,
            black,
            no markers,
            name path=A,
            ]
            {1/sqrt(2*pi)*exp(-.5*x^2)};
  \end{axis}
 \end{tikzpicture}
 \caption{Allgemeine Normalverteilung}
\label{eq:gauss}
\end{figure}


\end{document}[\code]

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

Beitrag von esdd »

Entferne hide y axis und ergänze
axis y line = middle,
enlarge y limits={.1,upper},
Also
\documentclass[12pt,a4paper,oneside, 
          BCOR=5mm, 
          %numbers=noenddot, 
          ] 
          {scrreprt} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 

\usepackage{pgfplots} 
\pgfplotsset{compat=newest} 
\usepgfplotslibrary{fillbetween} 
\usetikzlibrary{intersections} 


\begin{document} 
\begin{figure}[htbp] 
\centering 
  \begin{tikzpicture}[scale=1] 
   \begin{axis}[axis y line = middle,
                enlarge y limits={.1,upper},
                axis x line = bottom, 
                ytick=\empty, 
                x post scale = 2.25, 
                y post scale = 1.25, 
                xmin=-3.5,xmax=3.5, 
                xtick={-3,-2,-1,0,1,2,3}, 
                xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$}, 
                ] 
    \addplot+[samples = 50, 
             domain = -3.5:3.5, 
             black, 
             no markers, 
             name path=A, 
             ] 
             {1/sqrt(2*pi)*exp(-.5*x^2)}; 
   \end{axis} 
  \end{tikzpicture} 
  \caption{Allgemeine Normalverteilung} 
\label{eq:gauss} 
\end{figure} 
\end{document}
Das Paket pgfplots lädt übrigens tikz, das wiederum graphicx und xcolor lädt.

Siemo
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Di 9. Feb 2016, 08:54

Beitrag von Siemo »

Danke für die Hilfe.

Aber ich habe den Code gekürzt und färbe die Fläche unter der Kurve ein. Mit dem einfügen der y Achse, wird die Füllung unterdrückt, warum?

Hier ist der komplette Code des Diagramms.
\documentclass[12pt,a4paper,oneside,
			BCOR=5mm,
			%numbers=noenddot,
			]
			{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{fillbetween} 
\usetikzlibrary{intersections}

\begin{document}
	


\begin{figure}[htbp]
\centering
 \begin{tikzpicture}[scale=1]
  \begin{axis}[%axis y line = middle,
               %enlarge y limits={0.1,upper},
               axis x line = bottom,
               ytick=\empty,
               x post scale = 2.25,
               y post scale = 1.25,
               xmin=-3.5,xmax=3.5,
               xtick={-3,-2,-1,0,1,2,3},
               xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$},
               ]
   \addplot+[samples = 50,
            domain = -3.5:3.5,
            black,
            no markers,
            name path=A,
            ]
            {1/sqrt(2*pi)*exp(-.5*x^2)};
   \path[name path=B]
   (\pgfkeysvalueof{/pgfplots/xmin},0)--
   (\pgfkeysvalueof{/pgfplots/xmax},0);
   \addplot[gray] fill between[of=A and B,soft clip={domain=-3:3}];
   \addplot[gray!50] fill between[of=A and B,soft clip={domain=-2:2}];
   \addplot[gray!20] fill between[of=A and B,soft clip={domain=-1:1}];
   \node[fill=white,draw=black,anchor=center] at (0.5,0.15) {34\%};
   \node[fill=white,draw=black,anchor=center] at (-0.5,0.15) {34\%};
   \node[fill=white,draw=black,anchor=center] at (1.5,0.05) {13.5\%};
   \node[fill=white,draw=black,anchor=center] at (-1.5,0.05) {13.5\%};
   \node[fill=white,draw=black,anchor=center,pin={[pin distance=15mm]315:{}}] at (-3,0.1) {2.7\%};
   \node[fill=white,draw=black,anchor=center, pin={[pin distance=15mm]225:{}}] at (3,0.1) {2.7\%};
  \end{axis}
 \end{tikzpicture}
 \caption{Allgemeine Normalverteilung}
\label{eq:gauss}
\end{figure}


\end{document}

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

Beitrag von esdd »

Ich kann Dir jetzt nicht sagen, warum das passiert. Es scheint irgendetwas mit dem durch axis y line=middle gesetzten enlarge y limits=false zu tun zu haben. Wenn Du noch ymin=0 ergänzt, geht es wieder.
\documentclass[12pt,a4paper,oneside, 
          BCOR=5mm, 
          %numbers=noenddot, 
          ] 
          {scrreprt} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.13} 
\usepgfplotslibrary{fillbetween} 
%\usetikzlibrary{intersections} 

\begin{document} 

\begin{figure}[htbp] 
\centering 
  \begin{tikzpicture}[scale=1] 
   \begin{axis}[axis y line = middle,
                enlarge y limits={.1,upper},
                ymin=0pt,
                axis x line = bottom, 
                ytick=\empty, 
                x post scale = 2.25, 
                y post scale = 1.25, 
                xmin=-3.5,xmax=3.5, 
                xtick={-3,-2,-1,0,1,2,3}, 
                xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$}, 
                ] 
    \addplot+[samples = 50, 
             domain = -3.5:3.5, 
             black, 
             no markers, 
             name path=A, 
             ] 
             {1/sqrt(2*pi)*exp(-.5*x^2)}; 
    \path[name path=B] 
    (\pgfkeysvalueof{/pgfplots/xmin},0)-- 
    (\pgfkeysvalueof{/pgfplots/xmax},0); 
    \addplot[gray] fill between[of=A and B,soft clip={domain=-3:3}]; 
    \addplot[gray!50] fill between[of=A and B,soft clip={domain=-2:2}]; 
    \addplot[gray!20] fill between[of=A and B,soft clip={domain=-1:1}]; 
    \node[fill=white,draw=black,anchor=center] at (0.5,0.15) {34\%}; 
    \node[fill=white,draw=black,anchor=center] at (-0.5,0.15) {34\%}; 
    \node[fill=white,draw=black,anchor=center] at (1.5,0.05) {13.5\%}; 
    \node[fill=white,draw=black,anchor=center] at (-1.5,0.05) {13.5\%}; 
    \node[fill=white,draw=black,anchor=center,pin={[pin distance=15mm]315:{}}] at (-3,0.1) {2.7\%}; 
    \node[fill=white,draw=black,anchor=center, pin={[pin distance=15mm]225:{}}] at (3,0.1) {2.7\%}; 
   \end{axis} 
  \end{tikzpicture} 
  \caption{Allgemeine Normalverteilung} 
\label{eq:gauss} 
\end{figure} 
\end{document}
Oder Du verwendest die Sternvariante von axis y line, die nur die Position der Achse ändert und nimmst weitere Anpassungen selbst über Optionen vor.
\documentclass[12pt,a4paper,oneside, 
          BCOR=5mm, 
          %numbers=noenddot, 
          ] 
          {scrreprt} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.13} 
\usepgfplotslibrary{fillbetween} 
\usetikzlibrary{intersections} 

\begin{document} 

\begin{figure}[htbp] 
\centering 
  \begin{tikzpicture}[scale=1] 
   \begin{axis}[axis y line* = middle,
                y axis line style=->,
                ymin=0pt,
                hide obscured x ticks=false,
                axis x line = bottom, 
                ytick=\empty, 
                x post scale = 2.25, 
                y post scale = 1.25, 
                xmin=-3.5,xmax=3.5, 
                xtick={-3,-2,-1,0,1,2,3}, 
                xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$}, 
                ] 
    \addplot+[samples = 50, 
             domain = -3.5:3.5, 
             black, 
             no markers, 
             name path=A, 
             ] 
             {1/sqrt(2*pi)*exp(-.5*x^2)}; 
    \path[name path=B] 
    (\pgfkeysvalueof{/pgfplots/xmin},0)-- 
    (\pgfkeysvalueof{/pgfplots/xmax},0); 
    \addplot[gray] fill between[of=A and B,soft clip={domain=-3:3}]; 
    \addplot[gray!50] fill between[of=A and B,soft clip={domain=-2:2}]; 
    \addplot[gray!20] fill between[of=A and B,soft clip={domain=-1:1}]; 
    \node[fill=white,draw=black,anchor=center] at (0.5,0.15) {34\%}; 
    \node[fill=white,draw=black,anchor=center] at (-0.5,0.15) {34\%}; 
    \node[fill=white,draw=black,anchor=center] at (1.5,0.05) {13.5\%}; 
    \node[fill=white,draw=black,anchor=center] at (-1.5,0.05) {13.5\%}; 
    \node[fill=white,draw=black,anchor=center,pin={[pin distance=15mm]315:{}}] at (-3,0.1) {2.7\%}; 
    \node[fill=white,draw=black,anchor=center, pin={[pin distance=15mm]225:{}}] at (3,0.1) {2.7\%}; 
   \end{axis} 
  \end{tikzpicture} 
  \caption{Allgemeine Normalverteilung} 
\label{eq:gauss} 
\end{figure} 
\end{document}

Siemo
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Di 9. Feb 2016, 08:54

Beitrag von Siemo »

Entschuldigung erstmal für meine Späte Antwort.

Ich bedanke mich für die beiden Versionen, die beide mit Texpad (OSX) Editor nicht funktionierten.

Ich musste bei /pgfplotsset combat=newest setzten.

Den Code habe ich folgender Maßen geändert, nur Kleinigkeiten.
\documentclass[12pt,a4paper,oneside,
			BCOR=5mm,
			%DIV=calc,
			%numbers=noenddot,
			]
			{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=newest}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{figure}[htbp]
\centering
 \begin{tikzpicture}[scale=1]
  \begin{axis}[axis y line = middle,
               enlarge y limits={0.1,upper},
               ymin=0pt,
               axis x line = bottom,
               ytick=\empty,
               x post scale = 2.25,
               y post scale = 1.25,
               xmin=-3.5,xmax=3.5,
               xtick={-3,-2,-1,0,1,2,3},
               xticklabels={$\mu-3\sigma$,$\mu-2\sigma$,$\mu-\sigma$,$\mu$,$\mu+\sigma$,$\mu+2\sigma$,$\mu+3\sigma$},
               ]
   \addplot+[samples = 50,
            domain = -3.5:3.5,
            black,
            no markers,
            name path=A,
            ]
            {1/sqrt(2*pi)*exp(-0.5*x^2)};
   \path[name path=B]
   (\pgfkeysvalueof{/pgfplots/xmin},0)--
   (\pgfkeysvalueof{/pgfplots/xmax},0);
   \addplot[gray] fill between[of=A and B,soft clip={domain=-3:3}];
   \addplot[gray!50] fill between[of=A and B,soft clip={domain=-2:2}];
   \addplot[gray!20] fill between[of=A and B,soft clip={domain=-1:1}];
   \node[fill=white,draw=black,anchor=center] at (0.5,0.15) {34\%};
   \node[fill=white,draw=black,anchor=center] at (-0.5,0.15) {34\%};
   \node[fill=white,draw=black,anchor=center] at (1.5,0.05) {13.5\%};
   \node[fill=white,draw=black,anchor=center] at (-1.5,0.05) {13.5\%};
   \node[fill=white,draw=black,anchor=center,pin={[pin distance=15mm]315:{}}] at (-3,0.1) {2.7\%};
   \node[fill=white,draw=black,anchor=center, pin={[pin distance=15mm]225:{}}] at (3,0.1) {2.7\%};
  \end{axis}
 \end{tikzpicture}
 \caption{Allgemeine Normalverteilung}
\label{eq:gauss}
\end{figure}

\end{document}
Kann geschlossen werden !!

Antworten