繪製水平曲線(等高線)

繪製水平曲線(等高線)

因此,我憑藉 tikz 、 3dplot 和 pgfplots 的知識成功地做到了這一點:

\documentclass[11pt, oneside]{article}

\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer,patchplots}
\pgfplotsset{width=8cm,compat=1.14}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    domain = -3:3,
    y domain = -2:2,
    view = {0}{90},
    colormap={violet}{rgb=(0.3,0.06,0.5), rgb=(0.9,0.9,0.85)},
    point meta max=5,
    point meta min=-5,
    ]

    \addplot3[
        contour filled={number = 100,labels={false}}, 
        ]{(\x)^2 - 4*(\y)^2};

\draw (0,-2) -- (0,2) node[left,yshift=-.2cm]{$y$};
\draw (-3,0) -- (3,0) node[below,xshift=-.2cm]{$x$};
\draw[color=gray!60!black,dashed] (-2,2) -- (2,-2);
\draw[color=gray!60!black,dashed] (-2,-2) -- (2,2);

\end{axis}  
\end{tikzpicture}

\end{document}

得出: 輸出

現在為了使其完美,我只需要添加線條來顯示圖形的輪廓,更具體地說,例如 x^2 - 4*y^2 = 1 和 x^2 - 4*y^2 = 2現在這就是我被困的地方,不知道該怎麼做。但它應該看起來像這樣: 最終的

對此的任何幫助將不勝感激,並提前致謝,如果我使用錯誤的工具來做我想做的事情,您可以隨時為我指出正確的方向。

PS我知道最後一張圖片看起來很奇怪,但我畫了線來顯示它應該是什麼樣子,儘管我希望它代表上面給出的方程式。

答案1

這就是您正在尋找的東西?具體請看程式碼中的註解。

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.15,
        width=8cm,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        view={0}{90},
        domain=-3:3,
        y domain=-2:2,
        colormap={violet}{
            rgb=(0.3,0.06,0.5),
            rgb=(0.9,0.9,0.85)
        },
        point meta max=5,
        point meta min=-5,
    ]

        % changed how the surface is drawn
        % this is the "conventional" way to do so
        \addplot3 [
            surf,
            shader=interp,
        ] {x^2 - 4 * y^2};

        % add the contour lines
        \addplot3 [
            % increase a bit the number of samples so `smooth' does a good job
            samples=51,
            samples y=51,
            contour gnuplot={
                % state at which levels you want to draw the contour lines
                levels={1,2},
                % we don't want to add labels
                labels=false,
                % they should be drawn in black
                draw color=black,
                % and they should be smoothed
                handler/.style=smooth,
            },
        ] {x^2 - 4 * y^2};


        \draw (0,-2) -- (0,2) node [left,yshift=-.2cm]{$y$};
        \draw (-3,0) -- (3,0) node [below,xshift=-.2cm]{$x$};
        \draw [color=gray!60!black,dashed] (-2,2) -- (2,-2);
        \draw [color=gray!60!black,dashed] (-2,-2) -- (2,2);

    \end{axis}
\end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

相關內容