# How to make a plot from table data?

Having the following table:

How can we make a plot diagram showing the relation between P,Q? I would like the P-value on y-axis and the Q-values on the x-axis.

• The package pgfplotstable can do the job – Marco Daniel Jun 29 '13 at 18:43
• As Marco pointed out, pgfplotstable can do this right out of the box; it is especially convenient when you have the raw data as a CSV file. – Sean Allred Jun 29 '13 at 19:13

Here's a minimal example:

Assuming you have the data in a file (I called the file data.dat):

P $Q_A$ $Q_B$ $Q_D$
10 5 7 12
8 8 10 18
6 12 16 28


Use the code:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pagestyle{empty}
\begin{document}

\pgfplotstabletypeset{data.dat}

\vspace{1cm}

\begin{tikzpicture}
\begin{axis}[
xlabel=Q Series,
ylabel=P Values]
\addplot table [y=P, x=$Q_A$]{data.dat};
\addlegendentry{$Q_A$ series}
\addplot table [y=P, x=$Q_B$]{data.dat};
\addlegendentry{$Q_B$ series}
\addplot table [y=P, x=$Q_D$]{data.dat};
\addlegendentry{$Q_D$ series}
\end{axis}
\end{tikzpicture}

\end{document}


Check out the documentation for pgfplots. It's very well suited to creating graphs. I've only demonstrated the most basic possibilities. But it has a lot of power.

Note if you're going to use the package pgfplotstable then, technically, there's no need to load pgfplots. But, if you don't use pgfplotstable then be sure to load pgfplots to be able to graph your data.