`pgfplots` の軸をスケーリングして平方根関数をプロットする

`pgfplots` の軸をスケーリングして平方根関数をプロットする

unit vector ratio={2 1}このコードの何が問題なのでしょうか。平方根関数と立方根関数をより良く視覚化するために使用します。

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[height=4.5in,width=4.5in, clip=false,
    unit vector ratio={2 1},
    xmin=-100,xmax=100,
    ymin=-5,ymax=10,
    restrict y to domain=-5:10,
    xtick={\empty},ytick={\empty},
    enlargelimits={abs=1cm},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]

\addplot[samples=501, domain=0:100, blue] {x^(1/2)} node[anchor=north west, pos=0.75, font=\footnotesize]{$y = \sqrt{x}$};
\addplot[samples=501, domain=-100:0, green] {-(-x)^(1/3)}
node[anchor=south east, pos=0.25, font=\footnotesize]{$y = \sqrt[\uproot{1} \leftroot{-1} n]{x}$};
\addplot[samples=501, domain=0:100, green] {x^(1/3)};

\end{axis}
\end{tikzpicture}

\end{document}

答え1

unit vector ratio={2 1}-方向の単位ベクトルは、-方向のx単位ベクトルの 2 倍の長さですy。しかし、プロットの y 方向には 15 単位しかありませんが、-方向には 200 単位あります。したがって、 -軸の長さが 1cm のx場合、-軸の長さは 1cm*(200/15)*2=26.7cm でなければなりません。yx

unit vector ratio={1 4} 次のようなものを使うことをお勧めします。

ここに画像の説明を入力してください

コード:

\documentclass{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[height=4.5in,width=4.5in, clip=false,
    unit vector ratio={1 4},
    xmin=-100,xmax=100,
    ymin=-5,ymax=10,
    restrict y to domain=-5:10,
    xtick={\empty},ytick={\empty},
    enlargelimits={abs=1cm},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]
\addplot[samples=501, domain=0:100, blue] {x^(1/2)} node[anchor=north west, pos=0.75, font=\footnotesize]{$y = \sqrt{x}$};
\addplot[samples=501, domain=-100:0, green] {-(-x)^(1/3)}
node[anchor=south east, pos=0.25, font=\footnotesize]{$y = \sqrt[\uproot{1} \leftroot{-1} n]{x}$};
\addplot[samples=501, domain=0:100, green] {x^(1/3)};
\end{axis}
\end{tikzpicture}
\end{document}

コメント内の質問のため:

width=4.5inと を設定しますheight=4.5in。 と を設定しないと、unit vector ratio正方形になります。yminymax

ここに画像の説明を入力してください

\begin{axis}[height=4.5in,width=4.5in, clip=false,
    %unit vector ratio={1 4},
    xmin=-100,xmax=100,
    %ymin=-5,ymax=10,
    %restrict y to domain=-5:10,
    %xtick={\empty},ytick={\empty},
    ...
    ]

unit vector ratio={1 4}-軸のスケールは変化yしますが、それでも正方形のままです

ここに画像の説明を入力してください

\begin{axis}[height=4.5in,width=4.5in, clip=false,
    unit vector ratio={1 4},
    xmin=-100,xmax=100,
    %ymin=-5,ymax=10,
    %restrict y to domain=-5:10,
    %xtick={\empty},ytick={\empty},
    ...
    ]

しかし、とyを使用して表示される範囲を制限するyminと、軸ymaxの高さyが減少します。

ここに画像の説明を入力してください

\begin{axis}[height=4.5in,width=4.5in, clip=false,
    %unit vector ratio={1 4},
    xmin=-100,xmax=100,
    ymin=-5,ymax=10,
    %restrict y to domain=-5:10,
    %xtick={\empty},ytick={\empty},
    ...
    ]

答え2

与えられたコードは期待通りの結果をもたらします。主な問題は、間違ったパラメータをスケーリングしたために、間違った軸を圧縮したことです。

またwidth、、heightおよびすべての軸の制限 (つまり、、、、xminおよび)も提供されているため、問題は、実行する優先順位が高いのはどれか、またはキーの指定された順序によって決まるか、ということです。xmaxyminymax

すべてが期待どおりに動作することを示す簡略化されたコードを以下に示します。これが、ニーズに合わせてコードを変更するのに役立つことを願っていますが、質問が非常に「漠然としている」ため、これ以上お手伝いすることはできません。

\documentclass[border=2mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
    \usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
        % define a scaling factor for `unit vector ratio'
        \pgfmathsetmacro{\factor}{10}
        % define a lenght to draw in y direction for testing, 
        % if `unit vector ratio' is working as expected
        \pgfmathsetmacro{\Ydirection}{5}
    \begin{axis}[
        clip=false,
        unit vector ratio={1 \factor},
        restrict y to domain=-5:10,
        xlabel=$x$,ylabel=$y$,
    ]
        \addplot[samples=51, domain=0:100, blue] {x^(1/2)}
            node[anchor=north west, pos=0.75, font=\footnotesize]
                {$y = \sqrt{x}$};
        \addplot[samples=51, domain=0:100, green] {x^(1/3)};

        % draw some lines for testing, if the `unit vector ratio' is
        % working as expected and save the beginning and ending coordinates
        \draw [red] (0,0) -- +(axis direction cs: \factor*\Ydirection,0)
            coordinate [pos=0] (origin)
            coordinate [pos=1] (x)
        ;
        \draw [red] (0,0) -- +(axis direction cs: 0,\Ydirection)
            coordinate [pos=1] (y)
        ;
    \end{axis}
    \path   let
                % calculate "dummy" coordinates giving the coordinates
                % of the difference between the points
                % (because the one is at the origin it should give
                %  the same values as the first coordinate)
                \p1 = ($ (x) - (origin) $),
                \p2 = ($ (y) - (origin) $),
                % calculate the vector lengths of the "dummy points"
                \n1 = {veclen(\x1,\y1)},
                \n2 = {veclen(\x2,\y2)}
            in
                % plot the calculated length of the vectors, which should
                % be identical (if there are no rounding errors)
                node [anchor=west]  at (x) {\n1}
                node [anchor=south] at (y) {\n2}
    ;
\end{tikzpicture}
\end{document}

上記コードの結果を示す画像

関連情報