TransWikia.com

How to merge 2 tikzpictures into 1 (preserving coordinate system)

TeX - LaTeX Asked on February 6, 2021

(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.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP