Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
}

\newcommand{\func}[2][abmblue]{\addplot[color=#1] {#2};}

\newcommand{\parfunc}[3][abmblue]{\addplot[color=#1,domain=-200:200] ({#2},{#3});}
\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 
\let\globalappendtomacro=\pgfutil@g@addto@macro 
\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.

share|improve this question
    
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

1 Answer 1

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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.