如何對齊以下兩個圖表以使它們的 x 軸對齊?在這兩個圖中,y 軸的頂部都比我想要的要高。它的高度似乎在 13 到 14 之間。
\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3in,axis equal image,
axis lines=middle,
xmin=-4,xmax=8,samples=101,
xlabel=$x$,ylabel=$y$,
ymin=-2,ymax=10,
restrict y to domain=-2:10,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={2,10},ytick={},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-4:8] {x + 2} node [pos=0.9, anchor=north west, font=\footnotesize] {$y=f(x)$};
\draw [fill=white] (2,4) circle [radius=1.5pt] node[right,font=\tiny]{$(2, \, 4)$};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[width=3in,axis equal image,
axis lines=middle,
xmin=-4,xmax=8,samples=101,
xlabel=$x$,ylabel=$y$,
ymin=-2,ymax=10,
restrict y to domain=-2:10,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={2,10},ytick={},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-4:8] {x + 2} node [pos=0.9, anchor=north west, font=\footnotesize] {$y=g(x)$};
\draw [fill=white] (2,4) circle [radius=1.5pt] node[right,font=\tiny]{$(2, \, 4)$};
\draw [fill] (2,0) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\end{document}
答案1
若要使最大 y 值相同,請消除並指定兩個圖表所需enlargelimits
的值:ymax=11
筆記:
- 要使兩個圖表彼此相鄰,您需要消除
\end{tikzpicture}
和之間的空白行\begin{tikzpicture}
。 - 這還需要添加一個
left
選項來放置圖形標籤。
代碼:
\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3in,axis equal image,
axis lines=middle,
xmin=-4,xmax=8,samples=101,
xlabel=$x$,ylabel=$y$,
ymin=-2,ymax=11,
restrict y to domain=-2:10,
%enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={2,10},ytick={},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-4:8] {x + 2} node [pos=0.9, anchor=north west, font=\footnotesize, left] {$y=f(x)$};
\draw [fill=white] (2,4) circle [radius=1.5pt] node[right,font=\tiny]{$(2, \, 4)$};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[width=3in,axis equal image,
axis lines=middle,
xmin=-4,xmax=8,samples=101,
xlabel=$x$,ylabel=$y$,
ymin=-2,ymax=11,
restrict y to domain=-2:10,
% enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={2,10},ytick={},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-4:8] {x + 2} node [pos=0.9, anchor=north west, font=\footnotesize, left] {$y=g(x)$};
\draw [fill=white] (2,4) circle [radius=1.5pt] node[right,font=\tiny]{$(2, \, 4)$};
\draw [fill] (2,0) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}