2

I am trying to create a zoom effect for the plot on the left. I make a box in it and I want to draw lines from two corners of the rectangle going to the plot on the right. I thought it might be straightforward with \coordinate but pgfplots seems to forget the coordinate passing to another plot. Is there a possibility to make this effect using groupplots ?

enter image description here

Here is a MWE of my plots.

\documentclass{standalone}

\usepackage{mathtools} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \pgfplotsset{compat=1.18}

\begin{document} \begin{tikzpicture}[scale=0.7] \begin{groupplot}[group style={group size=2 by 1,ylabels at=edge left,}, xlabel=$X_\text{Cr}$,ylabel=$\mu$, ]

        \nextgroupplot[xmax=1.1,xmin=-0.1,ymax=30000,ymin=-23000]
        \draw (0,-21000) rectangle (0.2,10000);
        \coordinate (A) at (0,-21000);
        \coordinate (B) at (0.2,10000);

        \nextgroupplot[xmax=0.2,xmin=0,ymax=10100,ymin=-23000]

        \addplot coordinates {(0,-20000) (0.1,-10000) (0.18,9000)};

    \end{groupplot}
    \draw (A) -- (group c2r1.north west);
    \draw (B) -- (group c2r1.south west);
\end{tikzpicture}

\end{document}

Zarko
  • 296,517

1 Answers1

2

Problem solved by trying a different approach. It seems that the scale= option given to tikzpicture was messing with the coordinates and thus pointing the lines to nowhere. Since I always need to reduce the size of the picture, I used small option (see pgfplots documentation).

enter image description here

Here the MWE:

\documentclass{standalone}

\usepackage{mathtools} \usepackage{tikz} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \pgfplotsset{compat=1.18,}

\begin{document} \begin{tikzpicture} \begin{groupplot}[group style={group size=2 by 1,ylabels at=edge left,}, xlabel=$X_\text{Cr}$,ylabel=$\mu$,small,/tikz/font=\footnotesize, ]

        \nextgroupplot[xmax=1.1,xmin=-0.1,ymax=30000,ymin=-23000]
        \draw (0,-21000) rectangle (0.2,10000);
        \coordinate (A) at (0,-21000);
        \coordinate (B) at (0.2,10000);

        \nextgroupplot[xmax=0.2,xmin=0,ymax=10100,ymin=-23000]

        \addplot coordinates {(0,-20000) (0.1,-10000) (0.18,9000)};

    \end{groupplot}
    \draw (A) -- (group c2r1.south west);
    \draw (B) -- (group c2r1.north west);
\end{tikzpicture}

\end{document}

Vincent
  • 20,157