# Need help making a data table from \plot function in Tikz

I want to be able to generate a list of points from a plot in Tikz, with an adjustable interval and range for the x-values. So basically something like this:

++++++++++++++
+            +
+     ^      +
+    / \     +
+   /   \    +
+  /     \   +
++++++++++++++

X | Y
-------
-3 | 1
-2 | 2
-1 | 3
0  | 4
1  | 3
2  | 2
2  | 1


Here is a minimal working example:

\documentclass{article}
\usepackage{xcolor}
\usepackage{float}
\definecolor{abmorange}{HTML}{F7D700}
\definecolor{abmred}{HTML}{EB5448}
\definecolor{abmblue}{HTML}{2C90C6}
\definecolor{abmgreen}{HTML}{9DAB6F}
\definecolor{abmcream}{HTML}{FEFEDD}
\definecolor{abmyellow}{HTML}{EEEE00}
\usepackage{caption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.4}

\tikzset{
dim above/.style={to path={\pgfextra{
\pgfinterruptpath
\draw[>=latex,|<->|,black!50] let
\p1=($(\tikztostart)!2mm!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!2mm!-90:(\tikztostart)$)
in(\p1) -- (\p2) node[fill=black!5,pos=.5,sloped,above,font=\sffamily]{#1};
\endpgfinterruptpath
}
}
},
dim below/.style={to path={\pgfextra{
\pgfinterruptpath
\draw[>=latex,|<->|,black!50] let
\p1=($(\tikztostart)!2mm!90:(\tikztotarget)$),
\p2=($(\tikztotarget)!2mm!-90:(\tikztostart)$)
in (\p1) -- (\p2) node[pos=.5,sloped,below,font=\sffamily]{#1};
\endpgfinterruptpath
}
}
},
}

\newenvironment{plots}[2][10]{
\begin{figure}\centering
\caption{#2}
\begin{tikzpicture}
\begin{axis}[axis x line= middle, axis y line= middle, width=\textwidth, samples=50,grid=both, domain=-10:10, xmin=-#1, xmax=#1, ymin=-#1, ymax=#1, ultra thick, scale only axis, enlargelimits=false, anchor=origin, disabledatascaling]
}{
\end{axis}
\end{tikzpicture}
\end{figure}
}

\begin{document}
\begin{plots}{Parametric Function of a Hyperbola}
\parfunc{2+4/cos(x)}{-3+3*tan(x)}
\end{plots}
\end{document}


An additional note: I have figured out how to do a table using \foreach:

\pgfkeys{/pgf/number format/.cd,fixed,fixed zerofill,precision=3}
\makeatletter
\makeatother
\def\something{}
\foreach \i in {0,\the\numexpr2\relax,...,20}{
\pgfmathparse{cos(\i)}
\edef\temp{\i & \pgfmathresult\noexpand\\}
\expandafter\globalappendtomacro\expandafter\something\expandafter{\temp}
}

\begin{tabular}{rr}
\something
\end{tabular}


However, I have no clue how I would insert a parametric function into the \pgfmathparse{} command.

-
So you have the function and you want to evaluate it at certain points and print that as a table? –  Jake Mar 7 '13 at 17:40
Maybe you could post your TikZ code!? Your question is not easy to understand. –  Hans-Peter E. Kristiansen Mar 7 '13 at 17:45
Welcome to TeX.SE. This is doable, depending on how you are doing the plot, so it would be best if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. –  Peter Grill Mar 7 '13 at 17:49
@Jake exactly. I can post a mwe real quick. –  Adam Blum Mar 7 '13 at 17:55
I feel that you are looking for something like function graph cut from pgfplotstable but I don't know if your X values are given or computed. I mean are they the x values or the arguments of 2+4/cos(x)=-3 etc.? –  percusse Mar 7 '13 at 19:54

It turns out that the following is an answer to the question.

I've created a table from scratch to populate the function entries via having an array of values in column X and evaluation of the array via Y1 and Y2 columns with the functions given in the question.

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.7}
\begin{document}
\pgfplotstablenew[
create on use/X/.style={create col/set list={-3,...,3}},
create on use/Y1/.style={create col/expr={2+4/cos(\thisrow{X} r)}},
create on use/Y2/.style={create col/expr={-3+3*tan(\thisrow{X} r)}},
columns={X,Y1,Y2}, ]{7}{\mytable}

\pgfplotstabletypeset\mytable
\end{document}


-