我需要用 TiKZ 创建两个图形,一个在另一个里面。第一个较大的图形是通过绘制一些数据点制作的。较小的图形是一个带有一些矢量的半圆,我想将其放置在大图形的左下角(空白处)。我最初独立创建了这两个图形,因为我打算单独使用它们,但现在我想将它们合并为一个。这是我的代码的简化版本:
\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=3]
\begin{axis}[]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
% The code for the second smaller graphic starts here
%axes
\draw [ ->] (0,-0.1) -- (0,1.1);
\draw [ ->] (-1.1,0) -- (1.1,0);
%The two vectors
\draw [dotted] [ ->] [line width=0.2mm] (0,0) -- (0.707,0.707);
\draw [dotted] [ ->] [line width=0.2mm] (0,0) -- (-0.65,0.375);
%the semicricle
\clip (-1.2,0) rectangle (1.,1.);
\draw (0,0) circle (1cm);
\end{tikzpicture}
\end{document}
当我运行代码时,较小的图形被放置在原点,根据原始坐标,这显然不是我想要的。这是生成的图形的图片: 所以我想知道是否有办法取代它并重新调整其比例,以便我将它移动到空白处?
先感谢您!
答案1
正如评论中提到的,scope
环境允许您移动事物并重新缩放:
\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=3]
\begin{axis}[]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
% The code for the second smaller graphic starts here
\begin{scope}[shift={(2,1.5)},scale=1.33]
%axes
\draw [ ->] (0,-0.1) -- (0,1.1);
\draw [ ->] (-1.1,0) -- (1.1,0);
%The two vectors
\draw [dotted] [ ->] [line width=0.2mm] (0,0) -- (0.707,0.707);
\draw [dotted] [ ->] [line width=0.2mm] (0,0) -- (-0.65,0.375);
%the semicricle
\clip (-1.2,0) rectangle (1.,1.);
\draw (0,0) circle (1cm);
\end{scope}
\end{tikzpicture}
\end{document}