如何將 2 個 tikzpictures 合併為 1 個(保留座標系)

如何將 2 個 tikzpictures 合併為 1 個(保留座標系)

(問題沒那麼長,只是很多圖片和程式碼範例)

我正在嘗試合併兩個獨立的人tikzpictures,如下所示:

\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}

保留每個座標的原始座標。我希望能夠合併兩者以獲得相同的圖片,就像我所做的那樣:

\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}

(請不要回答「那麼,就這樣做」。我想從兩個獨立的 tikzpicture 中獲得該結果)

所以,原來的圖片是: 在此輸入影像描述 預期結果是: 在此輸入影像描述

我讀了:

在 TikZ 中合併繪圖

合併 Tikz 圖片

將兩個 tikz 圖合併在一起

但我認為唯一適合我的問題的是這個評論https://tex.stackexchange.com/a/96900/222098。我已經嘗試過這樣的解決方案:

\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}

結果是:

在此輸入影像描述

但該解決方案不會保留原始座標(而且我不想手動執行此操作)。其中一張圖片在新合併的圖片中似乎沒有正確的座標係比例。

相關內容