Seite 1 von 1

Integrale bei TikZ über den Achsen

Verfasst: Do 9. Mai 2019, 14:18
von ThoRie
Hallo, ich habe ein "Problem" mit folgendem Code:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
	\begin{axis}[
		domain=-2:2,
		samples=500,
		xmin=-2.2, xmax=2.2, xtick={1},
		ymin=-.1, ymax=1.1, ytick=\empty, yscale=.5,
		axis y line=center,
        axis x line=middle,
		]
		\addplot[draw=none,fill=yellow!30,domain=0:1]{exp(-1*x^2)}\closedcycle;
		\addplot+[name path=exp, mark=none,color=black] {exp(-1*x^2)};
		\path[name path=eins] (1,0)--(1,1);
		\path[name intersections={of= eins and exp, by=schnitt}];
		\draw[dashed] (1,0)--(schnitt);
	\end{axis}
\end{tikzpicture}
\end{document}
Und zwar gefällt mir die Grafik so an sich sehr gut, das einzige, was mich noch stört ist, dass die gefärbte Fläche über die Achsen ragt.
Das ist also das einzige, was sich in der Grafik ändern soll. Alles andere will ich genau so haben :)

Verfasst: Do 9. Mai 2019, 15:44
von esdd
Nimm die Option axis on top:
\documentclass{standalone} 
\usepackage{pgfplots}% lädt tikz, ...
\pgfplotsset{compat=newest} 
\begin{document} 
\begin{tikzpicture} 
   \begin{axis}[
      axis on top,% <- ergänzt
      domain=-2:2, 
      samples=500, 
      xmin=-2.2, xmax=2.2, xtick={1}, 
      ymin=-.1, ymax=1.1, ytick=\empty, yscale=.5, 
      axis y line=center, 
        axis x line=middle, 
      ] 
      \addplot[draw=none,fill=yellow!30,domain=0:1]{exp(-1*x^2)}\closedcycle; 
      \addplot+[mark=none,color=black] {exp(-1*x^2)}; 
      \draw[dashed] (1,0)--(1,{exp(-1)}); 
   \end{axis} 
\end{tikzpicture} 
\end{document}
Übrigens lädt pgfplotstable das Paket pgfplots, welches wiederum tikz lädt, ... Hier reicht aber pgfplots. Da die Funktion bekannt ist, habe ich den Funktionswert an der Stelle x=1 direkt ausrechnen lassen und deshalb auf die intersections Bibliothek verzichtet.

Verfasst: Do 9. Mai 2019, 19:02
von ThoRie
Okay vielen dank erstmal für die Hilfe mit dem eigentlichen Problem.

Und nochmal ganz besonderen Dank dafür, dass du mir sagst, dass tikz die Funktionswerte selbst berechnen kann. Ich mache nämlich immer wieder Grafiken, in denen ich die intersections benutze XD
Das macht mir meine Arbeit auch in Zukunft deutlich leichter :D