我需要在图形中叠加或嵌套一个图形。我尝试使用\pic
,但根据图形比例,图形比例的结果不佳。
我也尝试在节点中定义图形,并将其放置在图形中,但我做不到。
\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\tikzset{m2/.pic={
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
}}
\begin{figure}[!hbp]
\centering
\begin{minipage}[c]{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmin=-4000,x=.0035mm,y=1cm, axis x line=bottom,axis y line=left,clip=false]
\addplot[mark=none,red,very thick] coordinates{(406,8)(406,7)(823,7)(823,6)(1131,6)(1131,5)(1384,5)(1384,4)(1581,4)(1581,3)(1751,3)(1751,2)(1856,2)(1856,1)(1913,1)(1913,0)};
\addplot[mark=none,red,very thick] coordinates{(-406,8)(-406,7)(-823,7)(-823,6)(-1131,6)(-1131,5)(-1384,5)(-1384,4)(-1581,4)(-1581,3)(-1751,3)(-1751,2)(-1856,2)(-1856,1)(-1913,1)(-1913,0)};
\addplot[mark=none] coordinates{(0,0)(0,8)};
\end{axis}
\end{tikzpicture}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{minipage}[c]{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmax=5000,x=.0035mm,y=1cm, axis x line=bottom,hide y axis,clip=false]
\addplot[mark=none,red,very thick] coordinates{(822,8)(822,7)(1444,7)(1444,6)(1898,6)(1898,5)(2268,5)(2268,4)(2560,4)(2560,3)(2735,3)(2735,2)(2859,2)(2859,1)(2610,1)(2610,0)};
\addplot[mark=none,red,very thick] coordinates{(-822,8)(-822,7)(-1444,7)(-1444,6)(-1898,6)(-1898,5)(-2268,5)(-2268,4)(-2560,4)(-2560,3)(-2735,3)(-2735,2)(-2859,2)(-2859,1)(-2610,1)(-2610,0)};
\node at (axis cs: 2610,0.5) [font=\scriptsize, right] {$\sigma 2$};
\addplot[mark=none] coordinates{(0,0)(0,8)};
\pic [scale=50] at (500,400) {m2};
\end{axis}
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}
答案1
另一个技巧是在轴环境中定义坐标,然后稍后使用它们。注意:也可以使用相对坐标代替 xshift 和 yshift。
\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[!hbp]
\centering
\begin{minipage}[c]{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmin=-4000,x=.0035mm,y=1cm, axis x line=bottom,axis y line=left,clip=false]
\addplot[mark=none,red,very thick] coordinates{(406,8)(406,7)(823,7)(823,6)(1131,6)(1131,5)(1384,5)(1384,4)(1581,4)(1581,3)(1751,3)(1751,2)(1856,2)(1856,1)(1913,1)(1913,0)};
\addplot[mark=none,red,very thick] coordinates{(-406,8)(-406,7)(-823,7)(-823,6)(-1131,6)(-1131,5)(-1384,5)(-1384,4)(-1581,4)(-1581,3)(-1751,3)(-1751,2)(-1856,2)(-1856,1)(-1913,1)(-1913,0)};
\addplot[mark=none] coordinates{(0,0)(0,8)};
\end{axis}
\end{tikzpicture}
\end{minipage}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{minipage}[c]{0.4\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0,xmax=5000,x=.0035mm,y=1cm, axis x line=bottom,hide y axis,clip=false]
\addplot[mark=none,red,very thick] coordinates{(822,8)(822,7)(1444,7)(1444,6)(1898,6)(1898,5)(2268,5)(2268,4)(2560,4)(2560,3)(2735,3)(2735,2)(2859,2)(2859,1)(2610,1)(2610,0)};
\addplot[mark=none,red,very thick] coordinates{(-822,8)(-822,7)(-1444,7)(-1444,6)(-1898,6)(-1898,5)(-2268,5)(-2268,4)(-2560,4)(-2560,3)(-2735,3)(-2735,2)(-2859,2)(-2859,1)(-2610,1)(-2610,0)};
\node at (axis cs: 2610,0.5) [font=\scriptsize, right] {$\sigma 2$};
\addplot[mark=none] coordinates{(0,0)(0,8)};
\coordinate (bar) at (axis cs: 500,4);% save location for error bar
\end{axis}
%draw error bar
\pgfpointanchor{bar}{center}
\pgfgetlastxy{\tempx}{\tempy}
\begin{scope}[xshift=\tempx, yshift=\tempy, scale=0.3]
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
\end{scope};
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}
答案2
您需要使用来axis cs:
指定点的坐标。axis cs: 500,4
\pic [scale=50] at (axis cs: 500,4) {m2};
并且x=.006mm
(这太做作了),你会得到
答案3
根据egreg的回答,这里,我曾经picture
克服过这个问题。
的问题在于\pic
比例,插入的图片原本就不是按比例缩放的,它适合x
和中的图形比例。此外,使用y
很难处理。minipage
\pic
它们之间的区别如下图所示:
\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{graphicx,picture,calc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[htp]
\begin{minipage}[c]{0.4\linewidth}
\sbox0{
\begin{tikzpicture}[scale=.3]
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
\end{tikzpicture}
}
\sbox2{
\begin{tikzpicture}
\begin{axis}[ymin=0,xmax=5000,x=.0035mm,y=1cm, axis x line=bottom,hide y axis,clip=false]
\addplot[mark=none,red,very thick] coordinates{(822,8)(822,7)(1444,7)(1444,6)(1898,6)(1898,5)(2268,5)(2268,4)(2560,4)(2560,3)(2735,3)(2735,2)(2859,2)(2859,1)(2610,1)(2610,0)};
\addplot[mark=none,red,very thick] coordinates{(-822,8)(-822,7)(-1444,7)(-1444,6)(-1898,6)(-1898,5)(-2268,5)(-2268,4)(-2560,4)(-2560,3)(-2735,3)(-2735,2)(-2859,2)(-2859,1)(-2610,1)(-2610,0)};
\node at (axis cs: 2610,0.5) [font=\scriptsize, right] {$\sigma 2$};
\addplot[mark=none] coordinates{(0,0)(0,8)};
% \pic [scale=50] at (axis cs: 500,4) {m2};
\end{axis}
\end{tikzpicture}
}
\begin{picture}(\wd0, \ht0 )
\put(0,0){\usebox0}
%% Adjust the -0.7cm and -0.5cm shifts
\put(\wd0 - \wd2 - 0.5cm,\ht0 - \ht2 - 0.1cm){\usebox{2}}
\end{picture}
\end{minipage}
\begin{minipage}[c]{0.4\linewidth}
\sbox0{
\begin{tikzpicture}[scale=.3]
\draw (0,0)--(0,.4)--(1.575,.4)--(1.575,7.8)--(0,7.8)--(0,8.2)--(3.4,8.2)--(3.4,7.8)--(1.825,7.8)--(1.825,.4)--(3.4,.4)--(3.4,0)--cycle;
\end{tikzpicture}
}
\sbox2{
\begin{tikzpicture}
\begin{axis}[ymin=0,xmax=5000,x=.0035mm,y=1cm, axis x line=bottom,hide y axis,clip=false]
\addplot[mark=none,red,very thick] coordinates{(822,8)(822,7)(1444,7)(1444,6)(1898,6)(1898,5)(2268,5)(2268,4)(2560,4)(2560,3)(2735,3)(2735,2)(2859,2)(2859,1)(2610,1)(2610,0)};
\addplot[mark=none,red,very thick] coordinates{(-822,8)(-822,7)(-1444,7)(-1444,6)(-1898,6)(-1898,5)(-2268,5)(-2268,4)(-2560,4)(-2560,3)(-2735,3)(-2735,2)(-2859,2)(-2859,1)(-2610,1)(-2610,0)};
\node at (axis cs: 2610,0.5) [font=\scriptsize, right] {$\sigma 2$};
\addplot[mark=none] coordinates{(0,0)(0,8)};
% \pic [scale=50] at (axis cs: 500,4) {m2};
\end{axis}
\end{tikzpicture}
}
\begin{picture}(\wd0, \ht0 )
\put(0,0){\usebox0}
%% Adjust the -0.7cm and -0.5cm shifts
\put(\wd0 - \wd2 - 0.5cm,\ht0 - \ht2 - 0.1cm){\usebox{2}}
\end{picture}
\end{minipage}
\end{figure}
\end{document}