
Mithilfe von pgfplots zeichne ich die Isokontur einer Funktion f(x,y): Linien wie f(x,y)=C, wobei C eine gewählte Zahl ist.
Siehe unten ein Beispiel mit:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.85]
\begin{axis}[ xmin=-4,xmax=12, ymin=-4,ymax=4,x=1cm,y=1cm,at={(-4cm,-4cm)}]]
\addplot +[no markers,
raw gnuplot,
thick,dashed,
empty line = jump, % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
] gnuplot {
set contour base;
set cntrparam levels discrete -2,-1.1,-1.4;
unset surface;
set view map;
set isosamples 500;
set samples 500;
splot -2/sqrt((x-7.5)^2+y^2)-3/sqrt((x-0.5)^2+y^2);
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
Ich kann die Gradientenvektoren an jedem beliebigen Punkt zeichnen, weiß aber nicht, wie ich sie an verschiedenen Stellen auf der Isokonturkurve platzieren kann.
Wie kann ich die Positionen verschiedener Punkte auf dieser gestrichelten blauen Kurve ermitteln?
Antwort1
Man kann sich zunutze machen, dass man auf die Koordinaten der Konturplots zugreifen kann. Da es sich um mehrere unverbundene Segmente handelt, pos
reicht die Angabe nicht aus. Vielmehr muss zusätzlich verwendet werden pos segment
, was im pgfplots-Handbuch v1.16 auf S. 358 erklärt wird. Dabei ist allerdings nicht von vornherein klar, welches Segment welchen Index hat. Zur Vereinfachung habe ich einen Stil hinzugefügt, der den Gradientenpfeil hinzufügt, der an dieser Stelle orthogonal zur Tangente der Kontur steht.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{center}
\begin{tikzpicture}[gradient arrow/.style={
insert path={coordinate[pos=#1,sloped,
above=\pgfkeysvalueof{/tikz/ga/above}] (aux-1)
coordinate[pos=#1,sloped,
above=\pgfkeysvalueof{/tikz/ga/above}+\pgfkeysvalueof{/tikz/ga/length}] (aux-2)
(aux-1) edge[/tikz/ga/arrow]
(aux-2)}},ga/.cd,
above/.initial=3pt,
length/.initial=12pt,
arrow/.style={-stealth,black,solid,thick}]
\begin{axis}[scale=0.85,xmin=-4,xmax=12, ymin=-4,ymax=4,x=1cm,y=1cm,at={(-4cm,-4cm)}]]
\addplot +[no markers,name=contour,
raw gnuplot,
thick,dashed,
empty line = jump, % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
] gnuplot {
set contour base;
set cntrparam levels discrete -2,-1.1,-1.4;
unset surface;
set view map;
set isosamples 500;
set samples 500;
splot -2/sqrt((x-7.5)^2+y^2)-3/sqrt((x-0.5)^2+y^2);
}
[pos segment=1]
[gradient arrow/.list={0.2,0.8}]
[pos segment=3,/tikz/ga/arrow/.append style={red},/tikz/ga/length=10pt]
[gradient arrow/.list={0.2,0.8}];
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}