將一個 pgfplot 與另一個 pgfplot 上方對齊

將一個 pgfplot 與另一個 pgfplot 上方對齊

如何將描述解集的數軸移動到|3x - 5| - x < 17更接近 的圖形y = |3x - 5| - x

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

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



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



\begin{document}

\begin{tikzpicture}

\begin{axis}[name=plot1, width=2.75in, height=2.75in, axis x line=middle, axis y line=none, clip=false,
    domain=-5:15,
    xtick={-3, 11},ytick={\empty},
    ticklabel style={font=\scriptsize},
    xticklabels={-3, 11},
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
]

\addplot[draw=none] {0};

\draw[line width=1.2pt] (-3, 0) -- (11, 0);
\draw[draw=black, fill=white] (-3, 0) circle [radius=1.5pt];
\draw[draw=black, fill=white] (11, 0) circle [radius=1.5pt];

\end{axis}

\begin{axis}[at=(plot1.north), anchor=south, width=2.75in, height=2.75in, axis lines=middle, clip=false,
    axis lines=middle, clip=false,
    xmin=-8,xmax=18,
    ymin=-3,ymax=25,
    restrict y to domain=-3:25,
    xtick={-3,11}, ytick={\empty},
    ticklabel style={font=\scriptsize},
    xticklabels={\makebox[0pt][r]{$-$}3, 11},
    axis line style={latex-latex},
    xlabel=\textit{x},ylabel=\textit{y},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

\addplot[samples=2, blue, domain=-5:5/3] {-4*x + 5};
\addplot[samples=2, blue, domain=5/3:15] {2*x - 5};
\addplot[samples=2, latex-latex, domain=-8:18] {17};

%The equation for the piece of the function over the interval (-5, -15) is y = |3x - 5| - x.
\coordinate (A) at (14.5,24);
\coordinate (B) at (5/3,-5/3);
\coordinate (C) at (-8,17);

\end{axis}


%A "pin" is drawn between the label for the graph of y = |3x - 5| - x and a point on the graph.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A)!0.75cm!90:(B)$);
\node[blue, anchor=west, inner sep=0, font=\footnotesize] at ($(A)!0.75cm!90:(B)$) {\makebox[0pt][l]{$y = \vert3x - 5\vert - x$}};

%The label for the horizontal line is typeset.
\node[anchor=east, inner sep=0, font=\footnotesize] at ($(C) +(-0.15,0)$){$y = 17$};


\end{tikzpicture}


\end{document}

答案1

像這樣(我不確定你的問題是什麼。據我了解,問題的正文與標題無關)?

編輯: 顯然我不太明白你的問題。現在我猜你的問題也是圖之間的距離。所以我添加了第二個圖並將其高度降低1in。這樣x-axis,第二個圖與上圖底部之間的距離就減少了。

對於這兩個圖,我還定義了 common pgfplotsset,從而使程式碼更短一些:

編輯2: 如果您不喜歡將行指標指向函數的圖形,請將選項替換pinlabel

\documentclass{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc,intersections}

\begin{document}
    \begin{tikzpicture}[dot/.style = {circle, fill,inner sep=2pt}]
\pgfplotsset{
    width=2.75in,
    clip=false,
    xmin=-11,xmax=22,
    restrict y to domain=-3:25,
    xtick={-3,11},
    xticklabels={\makebox[0pt][r]{$-$}3, 11},
    ticklabel style={font=\scriptsize},
    xlabel=\textit{x},ylabel=\textit{y},
    xlabel style={at={(ticklabel* cs:1)}, above right},
    ylabel style={at={(ticklabel* cs:1)}, above right}
            }
\begin{axis}[name=plot1,
    height=2.75in,
    axis lines=middle,
    ymin=-3,ymax=25,
    ytick={\empty},
            ]
\addplot[samples=2, blue, domain=-5:5/3] {-4*x + 5};
\addplot[samples=2, blue, domain=5/3:15] {2*x - 5}
    coordinate[pos=0.9, label={[font=\footnotesize]0:$|3x - 5| - x < 17$}] (aux);  % <---
\addplot[samples=2, latex-latex, domain=-8:18] {17}
    node[font=\footnotesize,above left] {$y=17$};   % <---
\end{axis}
%
\begin{axis}[at=(plot1.south), anchor=north,
    height=1in, % minimal height which pgfplots accept is about 0.7 in
    axis x line=middle,
    axis y line=none,
]
\addplot[line width=1.2pt, mark=*] coordinates {(-3,0) (11,0)};
\end{axis}
    \end{tikzpicture}
\end{document}

現在上述 MWE 的結果是:

在此輸入影像描述

正確的答案是否給了您想要的內容?

相關內容