3

I’m trying to draw what’s on the picture. I’ve got no problem with drawing the two raw matrices but when it comes to the comments I’m a mess.

enter image description here

MWE:

 \documentclass[tikz]{standalone}
    \usetikzlibrary{matrix}
    \begin{document}
    \sffamily
    \begin{tikzpicture}
    \matrix (m) [matrix of nodes,nodes in empty cells,nodes={minimum size=.75cm,anchor=center}] {%
    & 5 &   & 2 & 4    &    &  &  \\
    4 &  & 3 & 1 &  &   & 3  &   \\
    & 5 & 4 &  & 5 &   & 4  &\\
    &   &   &  &   & 1 & 1 & 2   \\
    3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\
    & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\
    };
    \draw[step=0.75] (m-1-1.north west) grid (m-6-8.south east);
    \begin{scope}[font=\scriptsize]
    \foreach \i in {1,...,8} \path (m-1-\i.north) node[above] {\i};
    \foreach \i in {1,...,6} \path (m-\i-1.west)  node[left]  {\i};
    \end{scope}
    \path (m-1-5.north west) node[above=1em] {};
    \path (m-3-1.south west) node[left=1em] {};
    \end{tikzpicture}
    \end{document}
NaveganTeX
  • 2,630

1 Answers1

4

There is this very nice shapes.callout library for this.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,shapes.callouts}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,note/.style={rectangle callout, fill=#1}]
  \matrix (m) [matrix of nodes,nodes in empty cells,nodes={minimum size=.75cm,anchor=center}] {%
    & 5 &   & 2 & 4    &    &  &  \\
    4 &  & 3 & 1 &  &   & 3  &   \\
    & 5 & 4 &  & 5 &   & 4  &\\
    &   &   &  &   & 1 & 1 & 2   \\
    3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\
    & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\
    };
  \draw[step=0.75] (m-1-1.north west) grid (m-6-8.south east);
  \begin{scope}[font=\scriptsize]
   \path foreach \i in {1,...,8} {(m-1-\i.north) node[above] {\i}};
   \path foreach \i in {1,...,6} {(m-\i-1.west)  node[left]  {\i}};
  \end{scope}
  \path (m-1-5.north west) node[above=1em] {};
  \path (m-3-1.south west) node[left=1em] {};
  \path (m-3-8.east) + (0.3,0.5) node [anchor=south west,
  note=blue!50, opacity=.5,callout absolute pointer={(m-3-8.east)}]  {Active
  user};
\end{tikzpicture}
\end{document}

enter image description here

But as you are mentioning "cloud comments" I can't refrain from advertizing Kpym's nice answer here.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,shadows.blur,shapes}
\tikzset{
  % styles to save the path in `\savedpath`
  add path/.style = {
    decoration={show path construction,
      moveto code={
        \xdef\savedpath{\savedpath (\tikzinputsegmentfirst)}
      },
      lineto code={
        \xdef\savedpath{\savedpath -- (\tikzinputsegmentlast)}
      },
      curveto code={
        \xdef\savedpath{\savedpath .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast)}
      },
      closepath code={
        \xdef\savedpath{\savedpath -- cycle}
      }
    },
    decorate
  },
  store path/.style = {add path},
  store path/.prefix code={\xdef\savedpath{}},
  % the style to create the path
  callouts/.style={
    store path,
    append after command={
       foreach \target in {#1}{
        ($(callout)!2pt!-90:\target$)--\target --($(callout)!2pt!90:\target$)
      } \savedpath
    },
    alias=callout
  },
  % the style to display the callout
  custom style/.style={fill=blue!20,text=,blur shadow},
  % some fun cloudy node
  cloudy/.style={cloud,cloud puffs=10,cloud puff arc=120, aspect=2}
}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,note/.style={rectangle callout, fill=#1}]
  \matrix (m) [matrix of nodes,nodes in empty cells,nodes={minimum size=.75cm,anchor=center}] {%
    & 5 &   & 2 & 4    &    &  &  \\
    4 &  & 3 & 1 &  &   & 3  &   \\
    & 5 & 4 &  & 5 &   & 4  &\\
    &   &   &  &   & 1 & 1 & 2   \\
    3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\
    & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\
    };
  \draw[step=0.75] (m-1-1.north west) grid (m-6-8.south east);
  \begin{scope}[font=\scriptsize]
   \path foreach \i in {1,...,8} {(m-1-\i.north) node[above] {\i}};
   \path foreach \i in {1,...,6} {(m-\i-1.west)  node[left]  {\i}};
  \end{scope}
  \path (m-1-5.north west) node[above=1em] {};
  \path (m-3-1.south west) node[left=1em] {};
  \path[custom style] (m-3-8.east) + (0.3,0.5) 
  node[right,cloudy,callouts={(m-2-8.east),(m-4-8.east),(m-6-8.east)}]
  {many};
  \draw[decorate,decoration=brace] (m.south-|m-6-4.east) -- (m.south-|m-6-1.west)
  node[midway,below=0.5ex,,align=center] {Calculate \dots\\ Pft \dots};
\end{tikzpicture}
\end{document}

enter image description here

  • Awesome! Also, how can I draw the part where it says “calculate similarity of neighbors” and “calculate similarity of neighbors items”? With \underbrace maybe? – NaveganTeX Jun 22 '19 at 22:50
  • 1
    @naveganTeX Yes, I added such a brace to the second solution. You can use it in the first one, too, if you load decorations.pathreplacing there as well. –  Jun 22 '19 at 22:56
  • Great, looks sharp! Just wanted to mention that the brace points towards the beginning and the end of the columns and not to the middle. As it looks right now, it means that we're calculating similarity between columns 1,2,3 and 4. – NaveganTeX Jun 22 '19 at 22:58
  • 1
    @naveganTeX If you use (m.south-|m-6-4.center) -- (m.south-|m-6-1.center) instead of (m.south-|m-6-4.east) -- (m.south-|m-6-1.west) the brace will start at the middle of these cells. –  Jun 22 '19 at 23:01