2

I need overlay or nest a figure in a graph. I try with \pic, but the results aren't good for figure scale, according to graph scale.

I try also to define the figure in nodes, to place it in the graph, but I can't.

\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}
Isai
  • 4,153

3 Answers3

2

You need to use axis cs: for specifying the coordinates of the point. With axis cs: 500,4 in

\pic [scale=50] at (axis cs: 500,4) {m2};

and x=.006mm (it is too campy), you get

enter image description here

1

Another trick is to define coordinates inside the axis environment then use them later. Note: One can also use relative coordinates instead of xshift and yshift.

error bar

\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}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

Based on egreg answer, here, I used picture to overcome the problem.

The problem with \pic was the scale, the inserted picture was not originally scaled, it fit with the graph scale in x and y. Furthermore, it was difficult to handle minipages using \pic.

The difference between them is depicted in the picture:

2

\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}
Isai
  • 4,153