
pgfplots를 사용하여 함수 f(x,y)의 등고선을 그립니다. f(x,y)=C와 같은 선과 C가 선택한 숫자입니다.
아래 예를 참조하세요.
\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}
특정 지점에서 그라데이션 벡터를 그릴 수 있지만 등고선 곡선의 다른 위치에 배치하는 방법을 모르겠습니다.
파란색 점선 곡선에서 다양한 지점의 위치를 어떻게 얻을 수 있나요?
답변1
등고선 플롯의 좌표에 접근할 수 있다는 사실을 활용할 수 있습니다. 이들은 연결이 끊긴 여러 세그먼트이므로 지정하는 것만으로 pos
는 충분하지 않습니다. 대신, pos segment
3페이지에 설명된 을 사용해야 합니다 . pgfplots 매뉴얼 v1.16의 358. 그러나 어떤 세그먼트에 어떤 인덱스가 있는지는 명확하지 않습니다. 문제를 단순화하기 위해 이 지점에서 윤곽선의 접선에 직교하는 그라데이션 화살표를 추가하는 스타일을 추가했습니다.
\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}