使用不同列中的箭头和另一列中特定位置的文本对图像进行注释

使用不同列中的箭头和另一列中特定位置的文本对图像进行注释

我面临新的挑战,渴望学习有关 tikz 的知识。现在我需要参考图片的每个部分,我正在查看各种代码。下面是我想要实现的原始代码。我附上了一张图片以便更好地理解。这就是我想要设计的东西

 \documentclass[xcolor=dvipsnames, aspectratio=169, 11pt]{beamer}
    \usepackage{beamerthemeshadow}
    \usepackage[absolute,overlay]{textpos}
    \usepackage{tikz} \usetikzlibrary{tikzmark,calc}

\begin{document}
\section{}

\begin{frame}
    \frametitle{Components of Figure}
    \framesubtitle{Code}
        \scriptsize
        \begin{columns}[T] % align columns
        \begin{column}{0.5\textwidth}
            \color{Black}
    
    \texttt{import numpy as np\\
    import matplotlib.pyplot as plt\\
    from matplotlib.ticker import AutoMinorLocator, MultipleLocator\\
    np.random.seed(19680801)\\
    X = np.linspace(0.5, 3.5, 100)\\
    Y1 = 3+np.cos(X)\\
    Y2 = 1+np.cos(1+X/0.75)/2\\
    Y3 = np.random.uniform(Y1, Y2, len(X))\\
    fig = plt.figure(figsize=(8, 8))\\
    ax = fig.add\_subplot(1, 1, 1, aspect=1)\\
    def minor\_tick(x, pos):\\
    ~~~~if not x \% 1.0:\\
    ~~~~~~~~return ""\\
    ~~~~return f"{x:.2f}"\\    
    ax.xaxis.set\_major\_locator(MultipleLocator(1.000))\\
    ax.xaxis.set\_minor\_locator(AutoMinorLocator(4))\\
    ax.yaxis.set\_major\_locator(MultipleLocator(1.000))\\
    ax.yaxis.set\_minor\_locator(AutoMinorLocator(4))\\
   % # FuncFormatter is created and used automatically
   % #ax.xaxis.set\_minor\_formatter(minor\_tick)
   }
        
        \end{column}%
        \hfill%
        \begin{column}{.5\textwidth}
  \texttt{ }
        \begin{figure}
        \centering
     \includegraphics[height=0.7\textheight]{Img/components_of_graphs_1.png}
     \end{figure}
        \end{column}%
    \end{columns}
    



\end{frame}
\end{document}

我正在阅读下面的代码

\documentclass{article}
%\usepackage{showframe}
\usepackage{tikz}

\begin{document}
\noindent
\begin{tikzpicture}
\node [anchor=west] (note) at (-1,3) {\Large Note};
\node [anchor=west] (water) at (-1,1) {\Large Water};
\begin{scope}[xshift=1.5cm]
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.7\textwidth]{../images/EiffelWide.jpg}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[red,ultra thick,rounded corners] (0.48,0.80) rectangle (0.55,0.95);
        \draw [-latex, ultra thick, red] (note) to[out=0, in=-120] (0.48,0.80);
        \draw [-stealth, line width=5pt, cyan] (water) -- ++(0.4,0.0);
    \end{scope}
\end{scope}
\end{tikzpicture}%
\end{document}

但无法与之联系起来。所以在这里问你。这是注释的原始图像

答案1

以下是您可以使用的操作tikzmark

在 beamer 中注释图像

 \documentclass[xcolor=dvipsnames, aspectratio=169, 11pt]{beamer}
    \usepackage{beamerthemeshadow}
    \usepackage[absolute,overlay]{textpos}
    \usepackage{tikz} \usetikzlibrary{tikzmark,calc}

\begin{document}
\section{}

\begin{frame}
    \frametitle{Components of Figure}
    \framesubtitle{Code}
        \scriptsize
        \begin{columns}[T] % align columns
        \begin{column}{0.5\textwidth}
            \color{Black}
    
    \texttt{import numpy as np\\
    import matplotlib.pyplot as plt\\
    from matplotlib.ticker import AutoMinorLocator, MultipleLocator\\
    np.random.seed(19680801)\\
    X = np.linspace(0.5, 3.5, 100)\\
    \tikzmarknode{Y1}{Y1 = 3+np.cos(X)}\\
    \tikzmarknode{Y2}{Y2 = 1+np.cos(1+X/0.75)/2}\\
    \tikzmarknode{Y3}{Y3 = np.random.uniform(Y1, Y2, len(X))}\\
    fig = plt.figure(figsize=(8, 8))\\
    ax = fig.add\_subplot(1, 1, 1, aspect=1)\\
    def minor\_tick(x, pos):\\
    ~~~~if not x \% 1.0:\\
    ~~~~~~~~return ""\\
    ~~~~return f"{x:.2f}"\\    
    ax.xaxis.set\_major\_locator(MultipleLocator(1.000))\\
    ax.xaxis.set\_minor\_locator(AutoMinorLocator(4))\\
    ax.yaxis.set\_major\_locator(MultipleLocator(1.000))\\
    ax.yaxis.set\_minor\_locator(AutoMinorLocator(4))\\
   % # FuncFormatter is created and used automatically
   % #ax.xaxis.set\_minor\_formatter(minor\_tick)
   }
        
        \end{column}%
        \hfill%
        \begin{column}{.5\textwidth}
  \texttt{ }
        \begin{figure}
        \centering
     \includegraphics[height=0.7\textheight]{components_of_graphs_1.png}
     \end{figure}
        \end{column}%
    \end{columns}
    
    
    \begin{tikzpicture}[overlay,remember picture]
        \draw[blue,->] (Y1) to[out=0,in=180] (9.9,5);
        \draw[red,->] (Y2) to[out=0,in=200] (9.9,1.4);
        \draw[green!50!black,->] (Y3) to[out=0,in=200] (9.5,2.5);
    \end{tikzpicture}



\end{frame}
\end{document}

当然,您可以调整线条的参数:更改[out=<>,in=<>]、添加looseness,甚至创建更复杂的贝塞尔曲线。无论您需要什么。

相关内容