addplot コマンドを使用してスクリプト スタイルで目盛りにラベルを付け、矢印を線上に配置する

addplot コマンドを使用してスクリプト スタイルで目盛りにラベルを付け、矢印を線上に配置する

提供されたコードは、TikZ に y = (x^{2} - 4)/(x + 2) のグラフをプロットするように指示します。いくつかの変更が必要です。グラフは y = x - 2 の線のように見えます。この関数のグラフの両端に矢印を表示するにはどうすればよいでしょうか。

x 軸のラベル $x$ を右矢印の下やや右に配置するにはどうしたらよいでしょうか。また、y 軸のラベル $y$ を上矢印の上やや右に配置するにはどうしたらよいでしょうか。目盛り "-2" をscriptstyle白いボックス内にタイプセットするにはどうしたらよいでしょうか。点 (-2,0) と点 (-2,-4) の間の破線をその上に描画したくありません。y 軸を短くするにはどうしたらよいでしょうか。描画位置が低すぎます。

軸のコードに と という 2 つのコマンドがあります。xmax=8,ymax=7これらは TikZ に何を描画するように指示するのでしょうか?およびコマンドrestrict y to domain=-7:10がないのはなぜですか?xminymin

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}


\begin{document}

\hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[axis equal image,
          xmax=8,ymax=7,
          axis lines=middle,
          restrict y to domain=-7:7,
          enlargelimits={abs=1cm},
          axis line style={latex-latex},
          ticklabel style={fill=white},
          ytick=\empty,
          xtick={-2}
          %xlabel=$x$,ylabel=$y$,
]
\addplot[domain=-10:10,mark=none,samples=10] {x - 2} node [above left, yshift=3pt]{$\scriptstyle{y}=\frac{x^{\scriptscriptstyle{2}} - 4}{x + 2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left]{$\scriptstyle{(-2, \, -4)}$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

答え1

あなたはもうすでにこのことに気づいているはずですが、他の誰かがこれを見て疑問に思うかもしれないので。

  • 矢じり: 基本的には軸に使用したのと同じ方法で、オプション<->に追加します\addplot
  • 軸ラベルの位置: アンカーを変更する

    xlabel style={anchor=north west},
    ylabel style={anchor=south west}
    
  • 目盛りラベルのフォントサイズ:font=\scriptsizeに追加しますticklabel style
  • 線の下のチェックラベル: 簡単な方法はオプションaxis on topに追加することですaxis
  • xmin/ ymin: これらのキーが存在しないとなぜ言うのか理解できません。存在します。設定は、yminy 軸を短くする方法です。
  • restrict y to domain: まさにその通りだと思います。指定されたドメイン外の y 値を除外します。

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

\documentclass[10pt]{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
          axis on top, % added
          axis equal image,
          xmax=8,ymax=7,
          xmin=-3,ymin=-4,
          axis lines=middle,
          restrict y to domain=-7:7,
          enlargelimits={abs=1cm},
          axis line style={latex-latex},
          ticklabel style={fill=white,font=\scriptsize}, % added font
          ytick=\empty,
          xtick={-2},
          xlabel=$x$,ylabel=$y$,
          xlabel style={anchor=north west}, % added
          ylabel style={anchor=south west}, % added
]
\addplot[domain=-10:10,mark=none,samples=10,<->] {x - 2} node [above left, yshift=3pt]{$\scriptstyle{y}=\frac{x^{\scriptscriptstyle{2}} - 4}{x + 2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left]{$\scriptstyle{(-2, \, -4)}$};
\end{axis}
\end{tikzpicture}
\end{document}

関連情報