pgfplots:3D 函數的 2D 等高線圖:軸標籤的放置

pgfplots:3D 函數的 2D 等高線圖:軸標籤的放置

我正在使用 pgfplots\addplot3繪製二變量函數的等高線圖,如 (x,y) 平面所示(使用view={0}{90})。然而,軸標籤的預設位置很奇怪(我懷疑,因為它們在 3D 中的位置)。

我希望 x 位於 x 軸箭頭的右側,y 位於 y 軸箭頭的上方。我已經關注了這個問題,但更改錨點xlabel style似乎並沒有改變圖表上的任何內容。

微量元素:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
        % use `compat' level 1.8 or higher
        compat=1.8,
        % just put all the options in here and it will work as expected
        every axis/.append style={
            axis lines=center,
            xlabel style={anchor=south west},
            ylabel style={anchor=south west},
            zlabel style={anchor=south west},
            tick align=outside,
        },
    }
\begin{document}
 \begin{tikzpicture}[scale=0.85,font=\large]
 
 \begin{axis}[ ,
    axis lines=center,
    view={0}{90},
    xlabel=$x$, ylabel=$y$,     
    ]
 \addplot3 [
    contour gnuplot={levels={0.5,2}},
    domain=0:2,y domain=0:2
 ] {2*x*y };
 \end{axis}
 \end{tikzpicture} 
\end{document}

在此輸入影像描述

答案1

似乎定義軸標籤樣式並\pgfplotset沒有將樣式屬性傳遞給Gnuplot。因此,您必須在 axis 環境中定義它。您也可以透過以下方式控制標籤的位置:

x label style={at={(axis description cs:1.1,0.0)},anchor=center},

在此輸入影像描述

微量元素:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
        % use `compat' level 1.8 or higher
        compat=1.8,
    }
\begin{document}
 \begin{tikzpicture}[scale=0.85,font=\large]
 
 \begin{axis}[ ,
    axis lines=center,
    view={0}{90},
    xlabel=$x$, ylabel=$y$,
%    x label style={anchor=south west},
%    y label style={anchor=south west},
    x label style={at={(axis description cs:1.1,0.0)},anchor=center},
    y label style={at={(axis description cs:0.0,1.1)},anchor=center},
    ]
 \addplot3 [
    contour gnuplot={levels={0.5,2}},
    domain=0:2,y domain=0:2
 ] {2*x*y};
 \end{axis}
 \end{tikzpicture} 
\end{document}

PS:弗拉基米爾比我快......:)

答案2

您可以指定軸環境中軸標籤的位置。

在此輸入影像描述

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
    % use `compat' level 1.8 or higher
    compat=1.8,
    % just put all the options in here and it will work as expected
    every axis/.append style={
        axis lines=center,
        tick align=outside,
    },
}

\begin{document}
\begin{tikzpicture}[scale=0.85,font=\large]
 
 \begin{axis}[ ,
    axis lines=center,
    view={0}{90},
    xlabel style={right, yshift=5pt},
    ylabel style={above, xshift=5pt},
    xlabel=$x$, ylabel=$y$,
    domain=0:2,y domain=0:2,     
    ]
 \addplot3 [
    contour gnuplot={levels={0.5,2}},
    samples=50,
 ] {2*x*y };
 \end{axis}
 \end{tikzpicture} 
\end{document}

xshift參數yshift可以省略。

相關內容