Example: Graph within a table

Published 2014-03-20 | Author: Jake

We would like to plot a graph within a table column, similar to the weather data example.

We will use the booktabs package for good table design, and the multirow package.

The data is read using PGFPlotstable and the plot is typeset dynamically.

This code was written by Jake on TeX.SE.

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Graph within a table

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

% Read data file, create new column ``upper CI boundary - mean''
\pgfplotstableset{create on use/error/.style={
    create col/expr={\thisrow{uci}-\thisrow{mean}

% Define the command for the plot
  \begin{tikzpicture}[trim axis left,trim axis right]
        scale only axis,
        width             = 6.5cm,
        enlarge y limits  = {abs=0.5},
        axis y line*      = middle,
        y axis line style = dashed,
        ytick             = \empty,
        axis x line*      = bottom
      % ``mean'' must be present in the datafile,
      %``error'' is the newly generated column
      \addplot+[only marks][error bars/.cd,x dir=both, x explicit]
        table [x=mean,y expr=\coordindex,x error=error]{\data};

% Get number of rows in datafile

% Print the table
  % Booktabs rules
  every head row/.style = {before row=\toprule, after row=\midrule},
  every last row/.style = {after row=[3ex]\bottomrule},
  % Set header name
  columns/name/.style = {string type, column name=Name},
  % Use the ``error'' column to call the \errplot command in a multirow cell
  % in the first row, keep empty for all other rows
  columns/error/.style = {
    column name = {},
    assign cell content/.code = {% use \multirow for Z column:
    \pgfkeyssetvalue{/pgfplots/table/@cell content}
    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
  % Format numbers and titles
  columns/mean/.style = {column name = Mean, fixed ,fixed zerofill, dec sep align},
  columns/z/.style    = {column name = $z$, fixed, fixed zerofill, dec sep align},
  columns/p/.style    = {column name = $p$, fixed, fixed zerofill, dec sep align},
  columns/ci/.style   = {string type, column name = 95\% CI},
  % Create the ``(x to y)'' format, use \pgfmathprintnumber with `showpos`
  % to make things align nicely
  create on use/ci/.style={
    create col/assign/.code={\edef\value{(
      \noexpand\pgfmathprintnumber[showpos,fixed,fixed zerofill]{\thisrow{lci}}
      to \noexpand\pgfmathprintnumber[showpos,fixed,fixed zerofill]{\thisrow{uci}})}
      \pgfkeyslet{/pgfplots/table/create col/next content}\value


Adding comments is currently not enabled.