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 have a table in LaTeX format. I would like to plot a few figures using this data, having the five frequencies (125, 250, 500, 1000, 2000, 4000) on the horizontal axis, and the absorption coefficient between 0 and 1 on the vertical axis.

Is there a tool that supports LaTeX tables as data to plot from?

    \begin{tabular}{| l | l | l | l | l | l | l |}
\hline
Floor Materials & 
    125 Hz & 
    250 Hz & 
    500 Hz & 
1000 Hz & 
2000 Hz & 
4000 Hz \\ \hline


concrete or tile & 
0.01 & 
0.01 & 
0.015 & 
0.02 & 
0.02 & 
0.02 \\ 

linoleum/vinyl tile on concrete & 
0.02 & 
0.03 & 
0.03 & 
0.03 & 
0.03 & 
0.02 \\ 

wood on joists & 
0.15 & 
0.11 & 
0.10 & 
0.07 & 
0.06 & 
0.07 \\ 

parquet on concrete & 
0.04 & 
0.04 & 
0.07 & 
0.06 & 
0.06 & 
0.07 \\ 

carpet on concrete & 
0.02 & 
0.06 & 
0.14 & 
0.37 & 
0.60 & 
0.65 \\ 

carpet on foam & 
0.08 & 
0.24 & 
0.57 & 
0.69 & 
0.71 & 
0.73 \\ 

\hline
Seating Materials & 
    125 Hz & 
    250 Hz & 
    500 Hz & 
1000 Hz & 
2000 Hz & 
4000 Hz \\ \hline 


fully occupied - fabric upholstered & 
0.60 & 
0.74 & 
0.88 & 
0.96 & 
0.93 & 
0.85 \\ 

occupied wooden pews & 
0.57 & 
0.61 & 
0.75 & 
0.86 & 
0.91 & 
0.86 \\ 

empty - fabric upholstered & 
0.49 & 
0.66 & 
0.80 & 
0.88 & 
0.82 & 
0.70 \\ 

empty metal/wood seats & 
0.15 & 
0.19 & 
0.22 & 
0.39 & 
0.38 & 
0.30 \\ 

\hline
Wall Materials & 
    125 Hz & 
    250 Hz & 
    500 Hz & 
1000 Hz & 
2000 Hz & 
4000 Hz \\ \hline 


Brick: unglazed & 
0.03 & 
0.03 & 
0.03 & 
0.04 & 
0.05 & 
0.07 \\ 

Brick: unglazed \& painted & 
0.01 & 
0.01 & 
0.02 & 
0.02 & 
0.02 & 
0.03 \\ 

Concrete block - coarse & 
0.36 & 
0.44 & 
0.31 & 
0.29 & 
0.39 & 
0.25 \\ 

Concrete block - painted & 
0.10 & 
0.05 & 
0.06 & 
0.07 & 
0.09 & 
0.08 \\ 

Curtain: 10 oz/sq yd fabric molleton  & 
0.03 & 
0.04 & 
0.11 & 
0.17 & 
0.24 & 
0.35 \\ 

Curtain: 14 oz/sq yd fabric molleton & 
0.07 & 
0.31 & 
0.49 & 
0.75 & 
0.70 & 
0.60 \\ 

Curtain: 18 oz/sq yd fabric molleton & 
0.14 & 
0.35 & 
0.55 & 
0.72 & 
0.70 & 
0.65 \\ 

Fiberglass: 2'' 703 no airspace & 
0.22 & 
0.82 & 
0.99 & 
0.99 & 
0.99 & 
0.99 \\ 

Fiberglass: spray 5'' & 
0.05 & 
0.15 & 
0.45 & 
0.70 & 
0.80 & 
0.80 \\ 

Fiberglass: spray 1''  & 
0.16 & 
0.45 & 
0.70 & 
0.90 & 
0.90 & 
0.85 \\ 

Fiberglass: 2'' rolls & 
0.17 & 
0.55 & 
0.80 & 
0.90 & 
0.85 & 
0.80 \\ 

Foam: Sonex 2'' & 
0.06 & 
0.25 & 
0.56 & 
0.81 & 
0.90 & 
0.91 \\ 

Foam: SDG 3'' & 
0.24 & 
0.58 & 
0.67 & 
0.91 & 
0.96 & 
0.99 \\ 

Foam: SDG 4'' & 
0.33 & 
0.90 & 
0.84 & 
0.99 & 
0.98 & 
0.99 \\ 

Foam: polyur. 1'' & 
0.13 & 
0.22 & 
0.68 & 
1.00 & 
0.92 & 
0.97 \\ 

Foam: polyur. 1/2'' & 
0.09 & 
0.11 & 
0.22 & 
0.60 & 
0.88 & 
0.94 \\ 

Glass: 1/4'' plate large & 
0.18 & 
0.06 & 
0.04 & 
0.03 & 
0.02 & 
0.02 \\ 

Glass: window & 
0.35 & 
0.25 & 
0.18 & 
0.12 & 
0.07 & 
0.04 \\ 

Plaster: smooth on tile/brick & 
0.013 & 
0.015 & 
0.02 & 
0.03 & 
0.04 & 
0.05 \\ 

Plaster: rough on lath & 
0.02 & 
0.03 & 
0.04 & 
0.05 & 
0.04 & 
0.03 \\ 

Marble/Tile & 
0.01 & 
0.01 & 
0.01 & 
0.01 & 
0.02 & 
0.02 \\ 

Sheetrock 1/2"; 16"; on center & 
0.29 & 
0.10 & 
0.05 & 
0.04 & 
0.07 & 
0.09 \\ 

Wood: 3/8'' plywood panel & 
0.28 & 
0.22 & 
0.17 & 
0.09 & 
0.10 & 
0.11 \\  \hline

\end{tabular}

\begin{tabular}{| l | l | l | l | l | l | l |}
\hline
Ceiling Materials & 
    125 Hz & 
    250 Hz & 
    500 Hz & 
1000 Hz & 
2000 Hz & 
4000 Hz \\ \hline


Acoustic Tiles & 
0.05 & 
0.22 & 
0.52 & 
0.56 & 
0.45 & 
0.32 \\ 

Acoustic Ceiling Tiles & 
0.70 & 
0.66 & 
0.72 & 
0.92 & 
0.88 & 
0.75 \\ 

Fiberglass: 2'' 703 no airspace & 
0.22 & 
0.82 & 
0.99 & 
0.99 & 
0.99 & 
0.99 \\ 

Fiberglass: spray 5" & 
0.05 & 
0.15 & 
0.45 & 
0.70 & 
0.80 & 
0.80 \\ 

Fiberglass: spray 1"; & 
0.16 & 
0.45 & 
0.70 & 
0.90 & 
0.90 & 
0.85 \\ 

Fiberglass: 2'' rolls & 
0.17 & 
0.55 & 
0.80 & 
0.90 & 
0.85 & 
0.80 \\ 

wood & 
0.15 & 
0.11 & 
0.10 & 
0.07 & 
0.06 & 
0.07 \\ 

Foam: Sonex 2'' & 
0.06 & 
0.25 & 
0.56 & 
0.81 & 
0.90 & 
0.91 \\ 

Foam: SDG 3'' & 
0.24 & 
0.58 & 
0.67 & 
0.91 & 
0.96 & 
0.99 \\ 

Foam: SDG 4'' & 
0.33 & 
0.90 & 
0.84 & 
0.99 & 
0.98 & 
0.99 \\ 

Foam: polyur. 1'' & 
0.13 & 
0.22 & 
0.68 & 
1.00 & 
0.92 & 
0.97 \\ 

Foam: polyur. 1/2'' & 
0.09 & 
0.11 & 
0.22 & 
0.60 & 
0.88 & 
0.94 \\ 

Plaster: smooth on tile/brick & 
0.013 & 
0.015 & 
0.02 & 
0.03 & 
0.04 & 
0.05 \\ 

Plaster: rough on lath & 
0.02 & 
0.03 & 
0.04 & 
0.05 & 
0.04 & 
0.03 \\ 

Sheetrock 1/2'' 16"; on center  & 
0.29 & 
0.10 & 
0.05 & 
0.04 & 
0.07 & 
0.09 \\ 

Wood: 3/8"; plywood panel & 
0.28 & 
0.22 & 
0.17 & 
0.09 & 
0.10 & 
0.11 \\ 


\hline
Miscellaneous Material & 
    125 Hz & 
    250 Hz & 
    500 Hz & 
1000 Hz & 
2000 Hz & 
4000 Hz \\ \hline 


Water or ice surface & 
0.008 & 
0.008 & 
0.013 & 
0.015 & 
0.020 & 
0.025 \\ 

People (adults) & 
0.25 & 
0.35 & 
0.42 & 
0.46 & 
0.5 & 
0.5 \\ \hline

\end{tabular}
share|improve this question
3  
You will make life easier for yourself if you use a different inputformat (e.g. csv) and then typeset and plot from that. The pgfplotstable and pgfplots packages will easily allow you to do that. You can even use the tools from pgfplotstable to define the data inline and then plot using addplot table <your data table>; –  Martin Heller Jan 1 at 16:33
    
I see. A .csv format would be easy to construct from the current table; that is, if I can supply the values of each bar horizontally, instead of vertically like @I_Like_To_Code showed in his example. –  Qqwy Jan 1 at 16:46
    
See command \pgfplotstabletranspose from the pgfplotstable package. –  Martin Heller Jan 1 at 19:13

2 Answers 2

up vote 6 down vote accepted

There is a solution that does not do exactly what you want, but is extremely elegant in my admittedly biased opinion.

First, you put your data into a data file which is a text file. In my case, I named it 2014-01-01.txt.

freq    conc    lino
125     0.01    0.02
250     0.01    0.03
500     0.015   0.03
1000    0.02    0.03
2000    0.02    0.03
4000    0.02    0.02

Next, you use pgfplots to generate the plot, and pgfplotstable to generate the table, both reading from the data file

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\pgfplotstableset{% global config, for example in the preamble
  every head row/.style={before row=\toprule,after row=\midrule},
  every last row/.style={after row=\bottomrule},
  fixed,precision=2,
}

\begin{document}

\pgfplotstabletypeset[
  columns/freq/.style={column name=Frequency (Hz)},
  columns/conc/.style={column name=Concrete},
  columns/lino/.style={column name=Linoleum},
]{2014-01-01.txt}

\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
    xlabel={Frequency (Hz)},
    ylabel=Absorption Coefficient,
    legend pos=south east,
    legend entries={Concrete,Linoleum},
    ]
  \addplot table [x=freq,y=conc] {2014-01-01.txt};
  \addplot table [x=freq,y=lino] {2014-01-01.txt};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

Output:

enter image description here

Edited

The data file is now transposed so that each row corresponds to a material.

freq    125 250 500 1000    2000    4000
conc    0.01    0.01    0.015   0.02    0.02    0.02
lino    0.02    0.03    0.03    0.03    0.03    0.02

The code is similar except that we need to transpose the pgfplotstable object.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\pgfplotstableset{% global config, for example in the preamble
  every head row/.style={before row=\toprule,after row=\midrule},
  every last row/.style={after row=\bottomrule},
  fixed,precision=2,
}

\begin{document}    

\pgfplotstableread{2014-01-01-transpose.txt}\loadedtable
\pgfplotstabletranspose[colnames from={freq}]{\transposetable}{\loadedtable}

\pgfplotstabletypeset[string type]\loadedtable

\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
    xlabel={Frequency (Hz)},
    ylabel=Absorption Coefficient,
    legend pos=south east,
    legend entries={Concrete,Linoleum},
    ]
  \addplot table [x=colnames,y=conc] {\transposetable};
  \addplot table [x=colnames,y=lino] {\transposetable};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

share|improve this answer
    
pgfplots seems like a great tool creating slick graphics. However, do you know if it is possible to supply the values for the different bars after one another, instead of side-to-side? Otherwise I'd still need to fully rewrite everything. –  Qqwy Jan 1 at 16:43
    
There are many ways to create a csv file. 1. The easiest way is to key in the values in the text file manually. 2. You could key in the values in a Google Spreadsheet and transpose it by following the instructions in gappstips.com/docs-tips/view/113/… –  I Like to Code Jan 1 at 16:55
3  
pgfplotstable can also transpose tables - perhaps that would be a feasible improvement here? –  Christian Feuersänger Jan 1 at 21:58
    
Thanks Christian for the suggestion and for writing both pgfplots and pgfplotstable. I've implemented the transpose in the edited answer. –  I Like to Code Jan 2 at 1:08

Here is a solution using the S column type from siunitx for the table and pst-plot for the plot.

\documentclass{article}

\usepackage{pst-plot}
\usepackage[
%  locale = DE
]{siunitx}
\usepackage{booktabs}
\usepackage{filecontents}

\begin{filecontents*}{dataA.txt}
[[125,0.01],[250,0.01],[500,0.015],[1000,0.02],[2000,0.02],[4000,0.02]]
\end{filecontents*}
\readdata{\dataA}{dataA.txt}

\begin{filecontents*}{dataB.txt}
[[125,0.02],[250,0.03],[500,0.03],[1000,0.03],[2000,0.03],[4000,0.02]]
\end{filecontents*}
\readdata{\dataB}{dataB.txt}

\begin{document}

Table:

\bigskip

\begin{tabular}{
  S[table-format = 4]
  S[table-format = 1.3]
  S[table-format = 1.2]
}
  \toprule
   {Frequency} & {Concrete} & {Linoleum}\\
   {\si{\Hz}}  & {---}      & {---}     \\
  \midrule
    125 & 0.01  & 0.02\\
    250 & 0.01  & 0.03\\
    500 & 0.015 & 0.03\\
   1000 & 0.02  & 0.03\\
   2000 & 0.02  & 0.03\\
   4000 & 0.02  & 0.02\\
  \bottomrule
\end{tabular}

\bigskip

Data plot:

\bigskip

\begin{pspicture}(-1.6,-1.2)(8.5,6.4)
  \psaxes[
    dx = 1,
    Dx = 500,
    dy = 1,
    Dy = 0.005,
%    comma
  ]{->}(0,0)(0,0)(8.5,6.4)
  \rput{0}(4.25,-1.0){Frequency~(\si{\Hz})}
  \rput{90}(-1.45,3.2){Absorption Coefficient}
 \psset{
   plotstyle = line,
   showpoints,
   dotstyle = o
 }
  \pstScalePoints(1,1){500 div}{200 mul}
  \listplot[fillcolor = red]{\dataA}
  \listplot[fillcolor = blue]{\dataB}
\end{pspicture}

\end{document}

output

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.