Is it possible to draw like an inset style figure but just using tikz ? Obviously, I am trying to use the zoom effect by focusing on a particular region of a scheme but I want to achieve is :
- Inside the inset figure, I want to show a portion of the global profile in the red dot and then add the shape of the same profile but in the point at the end of the arrow. So these two profiles need to be present only in the zoomed region not in the whole picture : this is mainly why I am struggling here
How do you think it would be possible to achieve that ?
Thank you for your comments,
Best regards.
Code :
\documentclass{article}
\usepackage[utf8]{inputenc}
%%%%%%%%MATHS%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
%%%%%%%%GEOMETRIE%%%%%%%%%%%
\usepackage{geometry}
\usepackage{layout}
%%%AXIS%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%%%%%%%%SECTIONS/AGENCEMENT%%%
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{calc}
\usetikzlibrary{spy}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
\usepackage[framemethod=tikz]{mdframed} % breakable frames and coloured boxes
\usetikzlibrary{decorations.pathmorphing}
%%%%%%%%GAUSSIAN%%%%%%%%%%%%
\pgfmathdeclarefunction{gauss}{1}{%
\pgfmathparse{3*exp(-(#1/2.5)^2)}
}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[spy using outlines,
dot/.style = {circle, fill, inner sep=2.0pt, node contents={}},
scale = 1,
s/.style={shift=(0:9)}]
\fill [cyan!20]
plot[domain= -4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9})
|- (-4,0)
-| cycle;
\filldraw[fill=pink!20, thick]
plot[domain=-4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9)})
-- plot[domain=13:-4, samples=100] (\x, {gauss(\x)+gauss(\x-9)+0.2})
-- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);
\draw[dashed,red, stealth-stealth, thick] (-0.5,-2.25) -- node[below,scale=0.75] {$e \sim 1 \ mm$} (0.5,-2.25);
\draw yshift=-0.25cm, -latex -- node [fill=cyan!20,scale=0.75] {$Q_1$} (0,0);
\draw yshift=-0.25cm, -latex -- node [fill=cyan!20,scale=0.75] {$Q_2$} (9,0);
\spy [blue,draw,height=3cm,width=7cm,magnification=2,connect spies] on (4.5,0.85) in node at (4.5,5); % ZOOM EFFECT
\coordinate [red] (A) at (4.5,0.45) ;
\coordinate [red] (B) at (4.5,1.35) ;
\draw[dashed,-stealth,black!30!red,thick] (A) to (B) ;
\path (4.5,0.45) node[black!30!red,dot] ;
\end{tikzpicture}
\end{figure}
\end{document}
EDIT
I am trying to improve my previous attempt and I considered using a mixed solution as suggested in these posts : post1 and post2 by implementing a savebox feature and link 2 different graphs together
I am still not satisfied with it : for some reason I don't manage to understand the size of the node that I create for the second picture above that I want to be centered in the middle of the first main graph but didn't succeed to do that...
Second code :
\documentclass{article}
\usepackage[utf8]{inputenc}
%%%%%%%%MATHS%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amsfonts}
%%%%%%%%GEOMETRIE%%%%%%%%%%%
\usepackage{geometry}
\usepackage{layout}
%%%AXIS%%%%
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%%%%%%%%SECTIONS/AGENCEMENT%%%
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{calc}
\usetikzlibrary{spy}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
\usepackage[framemethod=tikz]{mdframed} % breakable frames and coloured boxes
\usetikzlibrary{decorations.pathmorphing}
%%%%%%%%GAUSSIAN%%%%%%%%%%%%
\pgfmathdeclarefunction{gauss}{1}{%
\pgfmathparse{3exp(-(#1/2.5)^2)}
}
\pgfmathdeclarefunction{gaussquatre}{1}{%
\pgfmathparse{3exp(-(#1/1.5)^2)}
}
%%%%% DOCUMENT%%%%%%
\begin{document}
\newsavebox\Graphone
\sbox\Graphone{\begin{tikzpicture}[spy using outlines,
dot/.style = {circle, fill, inner sep=1.5pt, node contents={}},
scale = 1,
s/.style={shift=(0:9)}]
\fill [cyan!20]
plot[domain= -4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9})
|- (-4,0)
-| cycle;
\filldraw[fill=pink!20, thick]
plot[domain=-4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9)})
-- plot[domain=13:-4, samples=100] (\x, {gauss(\x)+gauss(\x-9)+0.2})
-- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);
\draw[dashed,red, stealth-stealth, thick] (-0.5,-2.25) -- node[below,scale=0.75] {$e \sim 1 \ mm$} (0.5,-2.25);
\draw yshift=-0.25cm, -latex -- node [fill=cyan!20,scale=0.75] {$Q_1$} (0,0);
\draw yshift=-0.25cm, -latex -- node [fill=cyan!20,scale=0.75] {$Q_2$} (9,0);
\draw[black, pattern = checkerboard] (-0.5,-.5) -- (-0.5,0) -- (-4,0) -- (-4,-.5) -- cycle;
\draw[black, pattern = checkerboard] (9.5,-.5) -- (9.5,0) -- (13,0) -- (13,-.5) -- cycle;
\draw[black, pattern = checkerboard] (0.5,-.5) -- (0.5,0) -- (8.5,0) -- (8.5,-.5) -- cycle;
\end{tikzpicture}}
\newsavebox\Graphbis
\sbox\Graphbis{\begin{tikzpicture}[spy using outlines,
dot/.style = {circle, fill, inner sep=1.5pt, node contents={}},
scale = 1,
]
\fill [cyan!20]
plot[domain= 2.5:6.5, samples=100] (\x, {gauss(\x)+gauss(\x-9})
|- (-4,0)
-| cycle;
\filldraw[fill=pink!20, thin]
plot[domain=2.5:6.5, samples=100] (\x, {gauss(\x)+gauss(\x-9)})
-- plot[domain=6.5:2.5, samples=100] (\x, {gauss(\x)+gauss(\x-9)+0.1})
-- cycle;
\filldraw[fill=pink!20, thin]
plot[domain=2.5:6.5, samples=100] (\x, {gaussquatre(\x)+gaussquatre(\x-9)+1})
-- plot[domain=6.5:2.5, samples=100] (\x, {gaussquatre(\x)+gaussquatre(\x-9)+1.1})
-- cycle;
\coordinate [red] (A) at (4.5,0.3) ;
\coordinate [red] (B) at (4.5,1.1) ;
\draw[dashed,-stealth,black!30!red,thin] (A) to (B) ;
\path (4.5,0.285) node[black!30!red,dot] ;
\end{tikzpicture}}
%%%%%%FIGURE
\begin{figure}[h]
\centering
\begin{tikzpicture}
\node(a){\usebox{\Graphone}};
\node(b)[inner sep=0pt,above = 0.5cm of a] {\phantom{\usebox{\Graphbis}}};
\node(c)[draw,minimum size=0.5cm, at=(a)]{};
\begin{scope}[thin,blue!40]
\draw(c.north east) -- (b.south east);
\draw(c.north west) -- (b.south west);
\end{scope}
\node [at=(b),inner sep=0pt,above = 0.5cm of a] {\usebox{\Graphbis}};
\end{tikzpicture}
\end{figure}
\end{document}
Picture :






pgfplotsin your document, you don't need to loadpgfandtikzas they are loaded anyways. Also,tikzloads thexcolorpackage which is the successor of thecolorpackage which you should therefore probably not load. – Jasper Habicht Mar 07 '24 at 16:36