Graphics, Figures & Tablespgfplots with overlaying tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

pgfplots with overlaying tables

Post by theo moore »

Suppose I were to begin with a very simple plot constructed using pgfplots, such as so:

Code: Select all

\begin{figure} \centering
  \begin{tikzpicture}
  \begin{axis}[xlabel=$x$, ylabel=$y$, xmax=4]
	\addplot[mark=*] coordinates {(1,1) (2,2)};
  \end{axis}
  \end{tikzpicture}
\end{figure}
Notice that the xmax coordinate was set to 4, even though the highest x-coordinate is 2. I'd like to place a table of data ON TOP of this plot. That is, I'd like to use something like,

Code: Select all

\pgfplotstabletypeset[columns={$x$,$y$}] {data.dat};
almost like a legend.

I realize that the easiest fix would be to simply create two side-by-side figures, but is there a way to overlay things on-top of each other?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Re: pgfplots with overlaying tables

Post by php1ic »

I have no experience with pgfplots, but the overpic package sounds like the thing you are looking for

http://www.latex-community.org/forum/vi ... =45&t=6517

or search the forum, there are a few thread that discuss it
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots with overlaying tables

Post by localghost »

The pgfplots manual (Section 5.4.1 - Labels, p. 63f) mentions that you can add extra descriptions to the plot. This can be use to insert a small table in the plot area.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{booktabs}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[%
      extra description/.code={%
        font=\footnotesize
        \node[anchor=north east] at (0.95,0.95) {%
          \begin{tabular}{cc}\toprule
            $x$ & $y$ \\ \midrule
            1 & 2 \\
            2 & 1 \\ \bottomrule
          \end{tabular}
        };
      },
      xlabel=$x$,
      ylabel=$y$,
      xmax=4
    ]
      \addplot[mark=*] coordinates {(1,2) (2,1)};
    \end{axis}
  \end{tikzpicture}
\end{document}
At the moment I have no idea how this could be done in conjunction with the pgfplotstable package because my experience with that package is very limited. But the above code may serve as a basic structure. In case you succeed please post your final solution here.


Best regards
Thorsten
Post Reply