0

(Question is not that long, just a lots of images and code examples)

I'm trying to merge two independents tikzpictures like these:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{calc,math} \usetikzlibrary{shapes.misc} \usepackage{pgfplots}

\pgfplotsset{compat=newest} \pgfplotsset{my style/.append style={clip = false, axis lines* = middle, axis equal, xtick = \empty, ytick = \empty, xmin=-1, ymin=-1}}

\begin{document}

% First picture \begin{tikzpicture} \begin{axis}[my style] \addplot [green, fill, fill opacity=0.2, domain=0:360, samples=40] ({1+cos(x)0.8},{1+sin(x)0.8}); \end{axis} \end{tikzpicture} %Second picture \begin{tikzpicture} \begin{axis}[my style] \addplot [red] coordinates {(1,1)(0,0)}; \end{axis} \end{tikzpicture}

\end{document}

Preserving the original coordinates from each one. And I'd like to be able to merge both obtaining the same picture as if I'd do:

\begin{tikzpicture}
\begin{axis}[my style]
    \addplot [green, fill, fill opacity=0.2, domain=0:360, samples=40] ({1+cos(x)*0.8},{1+sin(x)*0.8});
    \addplot [red] coordinates {(1,1)(0,0)}; 
\end{axis}
\end{tikzpicture}

(Please don't answer "Then, just do that". I want to obtain that result from two independents tikzpictures)

So, the original pictures are: enter image description here And the expected result is: enter image description here

I've read:

Merging plots in TikZ

Combine Tikz pictures

Combining two tikz plots together

But I think the only thing that fits my problem is this comment https://tex.stackexchange.com/a/96900/222098. I've tried that solution this way:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{calc,math} \usetikzlibrary{shapes.misc} \usepackage{pgfplots}

\pgfplotsset{compat=newest} \pgfplotsset{my style/.append style={clip = false, axis lines* = middle, axis equal, xtick = \empty, ytick = \empty, xmin=-1, ymin=-1}}

\begin{document}

\begin{tikzpicture} \node [] at (0,0){ \begin{tikzpicture} \begin{axis}[my style] \addplot [green, fill, fill opacity=0.2, domain=0:360, samples=40] ({1+cos(x)0.8},{1+sin(x)0.8}); \end{axis} \end{tikzpicture} };

\node [] at (0,0){
    \begin{tikzpicture}
    \begin{axis}[my style]
    \addplot [red] coordinates {(1,1)(0,0)}; 
    \end{axis}
    \end{tikzpicture}
};

\end{tikzpicture}

\end{document}

And the result is:

enter image description here

But that solution doesn't preserve the original coordinates (and I'd prefer not to have to do it manually). One of the pictures seems to have not its correct coordinate system scale in the new merged one.

Blooment
  • 666
  • In general: don't nest tikzpictures: https://tex.stackexchange.com/a/46792. I don't know how one can do this, or if it's even possible, but what kind of limitations are there? Can one edit the code of the tikzpictures in any way? (If it were me, I'd comment out \end{axis}\end{tikzpicture} from the first, and \begin{tikzpicture}\begin{axis}[..] from the second, but that's not an option I take it.) – Torbjørn T. Aug 25 '20 at 17:11
  • Do you know if scope environment is able to support independents tikzpictures preserving coordinates axis? @TorbjørnT. – Blooment Aug 25 '20 at 17:20
  • I don't understand what you mean by that. – Torbjørn T. Aug 25 '20 at 17:21
  • I mean, in my solution, I nested two tikzpictures inside another one, and I'm asking if it would be possible to nest two tikzpictures inside a scope (By the way, I don't know how scope works) – Blooment Aug 25 '20 at 17:23
  • No, a scope only works inside a tikzpicture, it's purpose is to add the same options to a subset of the paths in the diagram. – Torbjørn T. Aug 25 '20 at 17:25
  • Thanks a lot. Right now I've read that it is possible to reuse one tikzpicture's coordinates after ending it with tikzpicture[remember picture], but I need the entire picture. – Blooment Aug 25 '20 at 18:41
  • You never answered the questions I asked in my first comment by the way. – Torbjørn T. Aug 26 '20 at 15:39

0 Answers0