Tikzpicture 范围背景图像

Tikzpicture 范围背景图像

我复制并修改了给出的代码http://www.texample.net/tikz/examples/swan-wave-model/

   \begin{figure}[H]
   \begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm},on grid]

    \begin{scope}[
            yshift=-83,every node/.append style={
            yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
            ]


        % opacity to prevent graphical interference
        \fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
        \draw[step=5mm, black] (0,0) grid (6,6); %defining grids
        \draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
        \draw[black,very thick] (0,0) rectangle (6,6);%marking borders
        \fill[red] (1,1) rectangle (1.5,1.5);
        %\includegraphics[scale=1,opacity=0.8]{Pics/face_patch}
        %Idem as above, for the n-th grid:
    \end{scope}

        \begin{scope}[
        yshift=90,every node/.append style={
        yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
                     ]
        \fill[white,fill opacity=.9] (0,0) rectangle (5,5);
        \draw[step=10mm, black] (1,1) grid (4,4);
        \draw[black,very thick] (1,1) rectangle (4,4);
        \draw[red,dashed] (0,0) rectangle (5,5);
    \end{scope}

        \draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
        to[out=180,in=90] (3.9,-1);

    \draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (3.6,5);
     \draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
        to[out=180,in=90] (0,5.7);


    \draw[-latex,thick,red,text=black](-3.3,-3.2)node[right]{$x_i$}
        to[out=180,in=90] (0,-1.4);

    \draw[-latex,dashed,red,text=black](4.3,-1.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (1,-1.3);

\end{tikzpicture}
\end{figure}

我想要插入一个具有一定不透明度的背景图片(以便网格以及底层颜色和网格/边框可见),以便图片成为第一个网格的背景(因此图像倾斜以匹配网格)

我该怎么做?执行纯 /includegraphics 根本不起作用(它没有标记图像,并且图像大小与网格大小不匹配)

答案1

您需要将 放置在\includegraphics内部\node,如下面的代码所示。我添加了一些注释,但它非常简单,主要是将节点放置在正确的位置,并为图像设置适当的大小。

在此处输入图片描述

\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}
   \begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm},on grid]

    \begin{scope}[
            yshift=-83,every node/.append style={
            yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
            ]


        % opacity to prevent graphical interference
        \fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
        \draw[step=5mm, black] (0,0) grid (6,6); %defining grids
        \draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
        \draw[black,very thick] (0,0) rectangle (6,6);%marking borders
        \fill[red] (1,1) rectangle (1.5,1.5); 

        % use a \node to add the image
        \node[
          opacity=0.5, % set opacity for node, \includegraphics has no opacity option
          anchor=south west, % which point of the node to place at the specified coordinate
          inner sep=0pt % no padding between image and node border
          ] 
          at (0,0) % actually default, so "at (0,0)" is strictly speaking not needed
          %
          % place the includegraphics in the node
          % your grid goes from 0 to 6 with scale=0.5, so its 3cm x 3cm
          % the image I used is quadratic, so I set just the width to 3cm
           {\includegraphics[width=3cm]{example-image-1x1}}; 

    \end{scope}

        \begin{scope}[
        yshift=90,every node/.append style={
        yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
                     ]
        \fill[white,fill opacity=.9] (0,0) rectangle (5,5);
        \draw[step=10mm, black] (1,1) grid (4,4);
        \draw[black,very thick] (1,1) rectangle (4,4);
        \draw[red,dashed] (0,0) rectangle (5,5);
    \end{scope}

        \draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
        to[out=180,in=90] (3.9,-1);

    \draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (3.6,5);
     \draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
        to[out=180,in=90] (0,5.7);


    \draw[-latex,thick,red,text=black](-3.3,-3.2)node[right]{$x_i$}
        to[out=180,in=90] (0,-1.4);

    \draw[-latex,dashed,red,text=black](4.3,-1.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (1,-1.3);

\end{tikzpicture}
\end{document}

答案2

真的只是为了好玩:就图形而言,它和Torbjørn T. 的回答很棒。“新”之处在于它使用了3d库和更多的符号坐标,因此可能更容易定制。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{3d}

\begin{document}
 \begin{tikzpicture}[scale=.5,x={({cos(30)},{sin(30)})},z={({-cos(30)},{cos(30)})},
 y={(0,1)}]

    \begin{scope}[canvas is xz plane at y=-2,transform shape]
         \draw[red] (0,0) -- (2,0);
        % opacity to prevent graphical interference 
        \fill[white,fill opacity=0.9] (0,0) rectangle (6,6);
        \node[opacity=0.3] at (3,3)
        {\includegraphics[width=6cm,height=6cm]{example-image}};
        \draw[step=5mm, black] (0,0) grid (6,6); %defining grids
        \draw[step=1mm, red!50,thin] (0.5,0.5) grid (2,2);  %Nested Grid
        \draw[black,very thick] (0,0) rectangle (6,6);%marking borders
        \fill[red] (1,1) rectangle (1.5,1.5) coordinate(x2);
        \coordinate (x3) at (1,2);
        \coordinate (x1) at (4,0);
    \end{scope}

        \begin{scope}[canvas is xz plane at y=3,transform shape]
        \fill[white,fill opacity=.9] (0,0) rectangle (5,5);
        \draw[step=10mm, black] (1,1) grid (4,4);
        \draw[black,very thick] (1,1) rectangle (4,4);
        \draw[red,dashed] (0,0) rectangle (5,5);
        \coordinate (y1) at (2.5,2.5);
        \coordinate (y2) at (4,0);
    \end{scope}

        \draw[-latex,thick](5.8,-.3)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{X}$}
        to[out=180,in=90] (x1);

    \draw[-latex,thick,text=black](5.9,5)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (y2);
     \draw[-latex,dashed,text=black](5.7,3)node[right]{$x_i$}
        to[out=180,in=90] (y1);


    \draw[-latex,thick,red,text=black](-3.3,-2.2)node[right]{$x_i$}
        to[out=180,in=90] (x2);

    \draw[-latex,dashed,red,text=black](4.3,-2.9)node[right]{$\mathsf{Skup\ svih\ piksela\ u\ } \boldsymbol{x}_i$}
        to[out=180,in=90] (x3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容