![显示两个相邻的图形,其 x 轴对齐](https://linux22.com/image/298763/%E6%98%BE%E7%A4%BA%E4%B8%A4%E4%B8%AA%E7%9B%B8%E9%82%BB%E7%9A%84%E5%9B%BE%E5%BD%A2%EF%BC%8C%E5%85%B6%20x%20%E8%BD%B4%E5%AF%B9%E9%BD%90.png)
如何对齐以下两个图表,使它们的 x 轴对齐?在这两个图表中,y 轴的顶部都比我想要的要高。它似乎在 13 到 14 之间的高度。我如何将它们的高度调整到 11?
\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}