2

I have the picture I inserted here to explain in my beamer presentation A stationary time series plot is drawn from pyplot in python

I drew the plot from python with a time series data. I want to explain the two dotted lines as I explain formula with this latex code

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\newcommand\tikzmark[1]{
\tikz[remember picture,overlay] \coordinate (#1);
}
\begin{document}
\begin{frame}
\frametitle{example}
\begin{block}{example}
    \[
    \tikzmark{ar}AR\tikzmark{i}I\tikzmark{ma}MA
    \]

    \begin{tikzpicture}[
    remember picture,
    overlay,
    expl/.style={draw=orange,fill=orange!30,rounded corners,text width=3cm},
    arrow/.style={red!80!black,ultra thick,->,>=latex}
    ]

    \node[expl]
    (artext)
    at (2,-2cm)
    {Autoregressive};
    \node[expl]
    (itext)
    at (4,3.5cm)
    {Integrated};
    \node[expl]
    (matext)
    at (9,-3cm)
    {Moving Average};

    \draw[arrow]
    (artext) to[out=100,in=180] ([yshift=0.ex]{ar});
    \draw[arrow]
    (itext.west) to[out=180,in=180] ([yshift=0.5ex]{i});
    \draw[arrow]
    (matext.east) to[out=0,in=0]([yshift=0.5ex]{ma});
    \end{tikzpicture}
    \end{block}
    \end{frame}
\end{document}

If it is not possible, how can I get this picture drawn in tikz and use arrows with boxed text to explain the two dotted lines?

here is my MWE for tex code

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz,graphicx}
\begin{document}
    \begin{frame}
    \frametitle{~}
    \begin{block}{~}
        \begin{figure}[H] 
            \includegraphics[width=\linewidth, height=3cm]{C:/Users/user/Desktop/storeimage.png}
        \end{figure}
    \end{block}
    \end{frame}
\end{document}

you can rigt-click to download the image and put it on your Desktop to make it your directory.

  • Please show a minimal but compilable code of the plot so that we can make some tests. – fractal Dec 21 '19 at 12:19
  • do you mean the python code? – Daniel James Dec 21 '19 at 12:20
  • 2
    No, the LaTeX code that you used to draw the plot. – fractal Dec 21 '19 at 12:21
  • the plot is drawn from python environment with a given time series data. I can only insert the chart into beamer environment – Daniel James Dec 21 '19 at 12:24
  • 1
    Yes, but to insert, you need TeX code right? Basically we need to have something so that we can have your plot in our computers, otherwise we can't test and therefore can't provide an answer. – fractal Dec 21 '19 at 12:25
  • I am looking for a way to point arrows to the 2 dotted lines in the plot like I pointed to the elements of formula i gave in MWE – Daniel James Dec 21 '19 at 12:27
  • Just use precisely the way your MWE used -- tikzmark. Or if your plot can be exported to TikZ, you can add arrows directly without tikzmark. That is all what I can say for now, as I can't reproduce your plot. – fractal Dec 21 '19 at 12:29
  • I have adde the MWE you call for – Daniel James Dec 21 '19 at 12:56
  • @DanielJames In order to precisely and conveniently point to the desired places in the image (assuming your plot stays as is), you can use this approach. Either do everything in a tikzpicture, or define coordinates in the wrapped picture (possibly using \tikzmark) for the “arrival points” of your arrows. In the latter case, pass remember picture to the tikzpicture containing the image and destination coordinates to make them visible from outside the tikzpicture, and overlay for the tikzpicture containing the arrows (for the bb). – frougon Dec 21 '19 at 12:59

2 Answers2

2

Sorry, during the last hour I did not really understand your question. You can read the previous versions of my answer in the revisions.


Well, you have to find the coordinate manually, which is not really convenient.

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\begin{document}
\begin{frame}
\frametitle{example}
\begin{block}{example}
\centering
\begin{tikzpicture}[remember picture]
  \path (0,0) node {\includegraphics[scale=0.5]{l9QEp.png}};
  % here you have to find the coordinates manually according to your diagram
  \coordinate (redline) at (-2,0);
  \coordinate (greenline) at (1.4,-1.3);
\end{tikzpicture}
\end{block}
\begin{tikzpicture}[remember picture,overlay,
  arrow/.style={red!80!black,ultra thick,>=latex},
  expl/.style={draw=orange,fill=orange!30,rounded corners,text width=3cm}]
  \draw[<-,arrow] (redline) to[out=120,in=-30] ++ (-1,3.5) node[anchor=-30,expl] {red line}; 
  \draw[<-,arrow] (greenline) to[out=-60,in=180] ++ (1,-2) node[right,expl] {green line};
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

However, I recommend using pgfplots and draw your plot from data instead of importing a PNG image. As you can see, when importing, PNG images get blurred, which is obviously not a good thing.

fractal
  • 1,500
2

Here is a solution based on Jake's answer here. The outer tikzpicture defines the interesting places we want to point to as nodes with the coordinate shape, called below e and below m in my examples. It uses the remember picture option to make these coordinates visible from outside the tikzpicture. The pictures that draw the arrows use the options remember picture (to be able to access the destination nodes by name, which are in another picture) and overlay (so as not to take any space on the page as far as TeX is concerned).

Of course, once you have found good coordinates for the destination points of the arrows you want to draw (which I call the “interesting places”), you should comment out or remove the code that draws the grid and the associated graduations—these are only here to help you find suitable coordinates for the “interesting places”.

First example

The following example uses text that is boxed inside a node with shape rounded rectangle as the source of the arrow—since the question mentions boxed text. rounded rectangle comes from the shapes.misc TikZ library.

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.misc}

\begin{document}

  \begin{frame}
    \frametitle{The frame title}
    \begin{figure}[H]
      \begin{tikzpicture}[remember picture]
        \node[anchor=south west, inner sep=0] (image) at (0,0)
          {\includegraphics[width=0.6\linewidth, height=3cm]{example-image}};
        \begin{scope}[x={(image.south east)}, y={(image.north west)},
                      every node/.style={font=\tiny}]
            \draw[help lines, xstep=.1, ystep=.1] (0,0) grid (1,1);
            \foreach \x in {0,1,...,9}
              { \node [anchor=north] at (\x/10,0) {0.\x}; }
            \foreach \y in {0,1,...,9}
              { \node [anchor=east] at (0,\y/10) {0.\y}; }
            % Define nodes here for the “interesting places” (i.e., where we
            % want the arrows to point to).
            \coordinate (below e) at (0.7,0.42);
        \end{scope}
      \end{tikzpicture}%
      \begin{tikzpicture}[remember picture, overlay]
        \draw node[rounded rectangle, draw=gray!80, fill=gray!10,
                   right=0.8em of image.east] (box) {Boxed text}
              (box) [->, red!60!black] to[out=-150, in=-70] (below e);
      \end{tikzpicture}
    \end{figure}

    This is below the picture.
  \end{frame}

\end{document}

screenshot 1st example

Second example

The following example uses a different technique: the arrows can start from anywhere you wish in the beamer slide. We draw two arrows, one that starts after a word or punctuation sign in a paragraph, and one that starts in the margin before the beginning of a paragraph (note that it is also possible, using \vadjust, to make an arrow start in the margin at the beginning or end of a line containing a particular word in the middle of a paragraph—that's essentially exercise 14.28 of the TeXbook, if you abstract the TikZ-based implementation).

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

  \begin{frame}
    \frametitle{The frame title}
    \begin{figure}[H]
      \begin{tikzpicture}[remember picture]
        \node[anchor=south west, inner sep=0] (image) at (0,0)
          {\includegraphics[width=0.6\linewidth, height=3cm]{example-image}};
        \begin{scope}[x={(image.south east)}, y={(image.north west)},
                      every node/.style={font=\tiny}]
            \draw[help lines, xstep=.1, ystep=.1] (0,0) grid (1,1);
            \foreach \x in {0,1,...,9}
              { \node [anchor=north] at (\x/10,0) {0.\x}; }
            \foreach \y in {0,1,...,9}
              { \node [anchor=east] at (0,\y/10) {0.\y}; }
            % Define nodes for interesting places (here: where we want the
            % arrows to point to).
            \coordinate (below e) at (0.7,0.42);
            \coordinate (below m) at (0.4,0.42);
        \end{scope}
      \end{tikzpicture}
    \end{figure}

    This is below the picture. Here is an arrow pointing below the ``e'' of
    our image: % one space token
    \begin{tikzpicture}[remember picture, overlay, baseline=-0.5ex]]
      \draw[->, red!80!black] (0,0) to[out=0, in=-120] (below e);
    \end{tikzpicture}

    \hspace*{-0.1em}% we'll start the second arrow in the left margin
    \begin{tikzpicture}[remember picture, overlay, baseline=-0.7ex]]
      \draw[->, blue!80!black] (0,0) to[out=180, in=-95] ++(-0.6em,5ex)
                                     to[out=85, in=-90] (below m);
    \end{tikzpicture}%
    \hspace{0.1em}%
    A second arrow pointing below the ``m''.
  \end{frame}

\end{document}

screenshot 2nd example

frougon
  • 24,283
  • 1
  • 32
  • 55