2

In the following MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\renewcommand{\a}{14.53}
\renewcommand{\b}{1.03}
\renewcommand{\c}{87.6}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
  scale only axis,
  xmin=0, xmax=80,
  axis x line=bottom
}

\begin{axis}[
  axis y line*=left,
  ymin=0, ymax=6,
  xlabel=Load (g),
  ylabel=Velocity of Shortening ($cm/s$),
  domain=0:80
]
\addplot[marks=o,marks only,samples=5] {\c/(x+\a)-\b+rand};
\end{axis}
\end{tikzpicture}
\end{document}

I am interested in adding a table below the tikzfigure, with the data points which are used by tikz to create the plot. Is this easily done? or is it easier to generate the data externally and then import it as coordinates in tikz?

2

Whether it's easier or not is up to you, but you can generate the table first using the features of pgfplotstable, and use that for the plot, as well as printing it after the plot with \pgfplotstabletypeset.

On another note, I think it's probably better to not redefine any existing macros, and units should not be written in italics, so I'd remove the $ around it.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\newcommand{\mya}{14.53}
\newcommand{\myb}{1.03}
\newcommand{\myc}{87.6}
\pgfplotstablenew[
% first create x-values
create on use/x/.style={
  create col/set list={0,20,...,80}},
% then create the random numbers
create on use/rand/.style={%
  create col/expr={\myc/(\thisrow{x}+\mya)-\myb+rand}},
% define columns in the table
columns={x,rand}
]
{5}% set number of rows in table
{\randomdata} % macro to save table in
\begin{document}

\begin{tikzpicture}
\pgfplotsset{
  scale only axis,
  xmin=0, xmax=80,
  axis x line=bottom
}

\begin{axis}[
  axis y line*=left,
  ymin=0, ymax=6,
  xlabel=Load (g),
  ylabel=Velocity of Shortening (cm/s),
  domain=0:80
]
\addplot[mark=o,only marks] table[x=x,y=rand] {\randomdata};
\end{axis}
\end{tikzpicture}

\pgfplotstabletypeset\randomdata
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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