2

Given a graphic done with pgfplots displaying a number of points (see example below) I would like to associate a pop up displaying a list of integer values (with 7 integers values in my example) when I move the mouse over such a point. I looked to the pdfcomment package (an more specifically to the example.tex file of the package showing the use of \pdftooltip for displaying things while moving the mouse over some point of a figure) but I have no idea how: 1) it is somehow possible to make pgfplot insert some command within nodes that it eventually creates. 2) I did also not completely understand the logic behing the arguments passed to \pdftooltip in the example.tex file of the pdfcomment package.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[xlabel={first},
             ylabel={second},
             title={Size: 7},
             minor tick num=1,
             grid=both,grid style={line width=.1pt, draw=gray!10},
             major grid style={line width=.1pt,draw=gray!10},
             xmin=-1,xmax=7,
             ymin=-1,ymax=7,
             scatter/classes={
              c1={mark=square*,blue!100},
              c2={mark=triangle*,blue!90},
              c3={mark=triangle*,blue!80},
              c4={mark=diamond*,blue!70},
              c5={mark=pentagon*,blue!60},
              c6={mark=*,blue!40},
              c7={mark=x,blue!30},
              c8={mark=+,blue!20},
              c9={mark=o,blue!10},
              c10={mark=o,green!30},
              c11={mark=o,green!20},
              c12={mark=o,green!10}}]
\addplot[scatter,only marks,
    scatter src=explicit symbolic]
    coordinates {
    (0, 0) [c1]
    (0, 1) [c1]
    (0, 2) [c1]
    (0, 3) [c1]
    (1, 4) [c2]
    (0, 4) [c2]
    (1, 5) [c3]
    (0, 5) [c4]
    (0, 6) [c6]
        };
\addplot[red]
    coordinates {
    (0,0)
    (0,6)
    (1,5)
    (1,4)
    (0,0)
        };
\end{axis}
\end{tikzpicture}
\end{document}

1 Answer 1

4

The usual trick is to place an extra node with invisible rectangle representing the tooltip:

tikz tootip example

With pgfplots you can do the same, but it does some magic with the coordinate system, so you will need some handwork! Maybe, there's another way I don't know.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pdfcomment}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[xlabel={first},
             ylabel={second},
             title={Size: 7},
             minor tick num=1,
             grid=both,grid style={line width=.1pt, draw=gray!10},
             major grid style={line width=.1pt,draw=gray!10},
             xmin=-1,xmax=7,
             ymin=-1,ymax=7,
             scatter/classes={
              c1={mark=square*,blue!100},
              c2={mark=triangle*,blue!90},
              c3={mark=triangle*,blue!80},
              c4={mark=diamond*,blue!70},
              c5={mark=pentagon*,blue!60},
              c6={mark=*,blue!40},
              c7={mark=x,blue!30},
              c8={mark=+,blue!20},
              c9={mark=o,blue!10},
              c10={mark=o,green!30},
              c11={mark=o,green!20},
              c12={mark=o,green!10}}]
\addplot[scatter,only marks,
    scatter src=explicit symbolic]
    coordinates {
    (0, 0) [c1]
    (0, 1) [c1]
    (0, 2) [c1]
    (0, 3) [c1]
    (1, 4) [c2]
    (0, 4) [c2]
    (1, 5) [c3]
    (0, 5) [c4]
    (0, 6) [c6]
        };
\addplot[red]
    coordinates {
    (0,0)
    (0,6)
    (1,5)
    (1,4)
    (0,0)
        };
\end{axis}
% this must be outside the axis environment!!!!
\node at (.85,.7) {\pdftooltip{\rule{0pt}{1mm}\rule{1mm}{0pt}}{c1}};
\node[draw=red] at (.85,5) {\pdftooltip{\rule{0pt}{1mm}\rule{1mm}{0pt}}{c6}};
\end{tikzpicture}
\hfill
\begin{tikzpicture}
    \draw [<->,thick] (0,2) node (yaxis) [above] {$y$}
        |- (3,0) node (xaxis) [right] {$x$};
    \draw (0,0) coordinate (a_1) -- (2,1.8) coordinate (a_2);
    \draw (0,1.5) coordinate (b_1) -- (2.5,0) coordinate (b_2);
    \coordinate (c) at (intersection of a_1--a_2 and b_1--b_2);
    \draw[dashed] (yaxis |- c) node[left] {$y'$}
        -| (xaxis -| c) node[below] {$x'$};
    %
    \fill[red] (0,0) circle (2pt);
    \draw (0,0) node {\pdftooltip{\rule{0pt}{0.5cm}\rule{0.5cm}{0pt}}{Origin}};
    %
    \draw[red] (1.5,2) node {\pdftooltip{\textbullet}{1.5,2.0}};
    %
    \fill[red] (c) circle (2pt)
    let
        \p1 = (current path bounding box.south west),
        \p2 = (current path bounding box.north east)
    in
    node at (current path bounding box)
    {\pdftooltip{\rule{\dimexpr\x2-\x1\relax}{0pt}\rule{0pt}{\dimexpr\y2-\y1\relax}}%
    {This is the intersection point\textCR of the two lines!}};   
\end{tikzpicture}
\end{document}

pgfplots annotation example

However, pgfplots has its own way to implement annotations using Javascript, which will only work with Adobe (Reader), see section '5.1 Clickable Plots' in the documentation!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .