In answering How do I create a combined figure with two imported curves and draw around it with Tikz?, I was able to make my own graph fill the space between two horizontal lines as seen here. However, when I tried to import a dat file, I ran into difficulties.
My first problem was scaling. I thought I could use the key height to fix the height of the image. But it's not behaving as I thought it would:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\def\myimage#1{%%
\begin{tikzpicture}%%[x=#1,y=#1]
\begin{axis}[
height=#1,
hide axis,
no markers,
]
\addplot + table[x index=0, y index=1]{vp1.dat};
\end{axis}
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- ++(6,0)
(0,4) -- ++(6,0);
\node[inner sep=0pt,draw,red] at (3,2) {\myimage{4cm}};
\end{tikzpicture}
\end{document}

I wanted it so that the red box's top and bottom should be flush with the black horizontal lines.
My second problem was getting rid of all the white space. I would like the bounding box for the graph to fit as tightly as possible when I've hidden the axes. In other words, the red border should be snug up against the blue of the graph.
Here's my vp1.dat file:
1 3
2 4
3 -5
4 6
Here's my vp2.dat file:
1 3
2 4
3 1
4 3
Update
I have partial solutions to my questions but no combined solution.
Solution to first problem
Regarding the first problem, I can get the pgfplot to fill the desired effect by using a combination of
scale only axis
height=#2
MWE:
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\def\myimage#1#2{%%
\begin{tikzpicture}
\begin{axis}[
scale only axis,
height=#2,
hide axis,
no markers,
]
\addplot + table[x index=0, y index=1]{#1};
\end{axis}
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- ++(6,0)
(0,4) -- ++(6,0);
\node[anchor=south] at (3,4) {\texttt{height=4cm} passed to \texttt{pgfplots}};
\node[inner sep=0pt,draw,red] at (3,2) {\myimage{vp1.dat}{4cm}};
\draw[<->] (6.25,0) -- ++(0,4) node [midway,right]{4cm};
\end{tikzpicture}
\end{document}
which results in:

Solution to second problem
Regarding the second problem, I can get the pgfplot to trim the extra white space that I do not want by using both
clip bounding box=upper bound
hide axis
MWE:
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\def\myimage#1#2{%%
\begin{tikzpicture}
\begin{axis}[
clip bounding box=upper bound,
hide axis,
no markers,
]
\addplot + table[x index=0, y index=1]{#1};
\end{axis}
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\node[anchor=south] at (3,4.35) {graph fits snuggly in its bounding box};
\node[inner sep=0pt,draw,red] at (3,2) {\myimage{vp1.dat}{4cm}};
\end{tikzpicture}
\end{document}
which results in:

No solution for combined approach
But when I try to combine both methods, the height is not obeyed properly and I can't figure out how it's being calculated.
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\def\myimage#1#2{%%
\begin{tikzpicture}
\begin{axis}[
scale only axis,
clip bounding box=upper bound,
height=#2,
hide axis,
no markers,
]
\addplot + table[x index=0, y index=1]{#1};
\end{axis}
\end{tikzpicture}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- ++(6,0)
(0,4) -- ++(6,0);
\node[anchor=south] at (3,4) {combining \texttt{clipping} and \texttt{height}};
\node[inner sep=0pt,draw,red] at (3,2) {\myimage{vp1.dat}{4cm}};
\draw[<->] (6.25,0) -- ++(0,4) node [midway,right]{4cm};
\end{tikzpicture}
\end{document}
which results in:



pgfplots. With nodes intikzyou can specifyinner sep=0ptto eliminate extra white space about the node. But, I can't do that here. For some reasonpgfplotsis maintaining the space dedicated to the axes even though I don't want to see them. How can I eliminate that dedicated space? – A.Ellett Apr 11 '14 at 02:04pgfplotsto achieve this. – A.Ellett Apr 11 '14 at 02:05clip bounding box=upper boundwhen used in conjunction withhide axis. – A.Ellett Apr 11 '14 at 02:18tikzpictureas the drawing is done as per thex,yunit vectors of thetikzpicture. – Peter Grill Apr 11 '14 at 02:26pgfplotspicture contained in a node. It's to thepgfplots'axisenvironment that I'm passingheight. – A.Ellett Apr 11 '14 at 02:28