0

I'm looking for a method to display multivariate data with a parallel coordinate plot and want to make the figure in pgfplots because my whole document uses pgfplots for the figures. The way this plot looks is rather simple. Example is given here.

Does anyone have any clue on how to make the connecting lines with pgfplots?

Making each axis seems rather simple, but I can't figure out how to connect the point of each axis. My input data is a simple matrix with c columns (= result set) and l lines (number of simulation runs).

  • 2
    Welcome to TeX.SX! Would you be so kind as to provide a minimal working example (MWE) of how far you have gotten? This will greatly help us help you. – sk8forether Jun 8 '17 at 14:16
  • Instead of overlaying bunch of pgfplots, I would scale the data and plot the whole thing in one go (axis lines=none), then overlay the different axes using regular tikz. – John Kormylo Jun 8 '17 at 14:25
  • @JohnKormylo do you have a rough overview for me what you mean? can't figure it out exactly. – ayayhuibui Jun 8 '17 at 14:39
  • Can you create an MWE by entering some fake data using pgfplotstable? – John Kormylo Jun 8 '17 at 15:10
2

This is inefficient enough that it might not be interesting, but in case it is. iris.dat is a text file with the iris dataset, so it has header row + 150 data rows and 4 columns.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{pgfplotstable}
% read in data file
\pgfplotstableread{iris.dat}\iris
% get number of data points
\pgfplotstablegetrowsof{\iris}
\pgfmathsetmacro\NumRows{\pgfplotsretval-1}

\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.14}
\begin{document}

\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name=iris,
    group size=4 by 1,
    horizontal sep=2cm
  },
  axis y line=left,
  hide x axis,
  width=2cm,
  height=6cm,
  xmin=0,
  xmax=0.5,
  enlarge y limits,
  every axis plot/.append style={opacity=0}
]

\nextgroupplot

\pgfplotsinvokeforeach{0,...,\NumRows} % loop over all rows in table
{
  % get value in sw column
  \pgfplotstablegetelem{#1}{sw}\of{\iris}%
   % add a coordinate at x=0 and that y-value
  \edef\temp{\noexpand\addplot coordinates {(0,\pgfplotsretval)} coordinate (sl#1);}
  \temp
}

\nextgroupplot

\pgfplotsinvokeforeach{0,...,\NumRows}
{
  \pgfplotstablegetelem{#1}{sl}\of{\iris}%
  \edef\temp{\noexpand\addplot coordinates {(0,\pgfplotsretval)} coordinate (sw#1);}
  \temp
}

\nextgroupplot

\pgfplotsinvokeforeach{0,...,\NumRows}
{
  \pgfplotstablegetelem{#1}{pw}\of{\iris}%
  \edef\temp{\noexpand\addplot coordinates {(0,\pgfplotsretval)} coordinate (pl#1);}
  \temp
}

\nextgroupplot

\pgfplotsinvokeforeach{0,...,\NumRows}
{
  \pgfplotstablegetelem{#1}{pl}\of{\iris}%
  \edef\temp{\noexpand\addplot coordinates {(0,\pgfplotsretval)} coordinate (pw#1);}
  \temp
}

\end{groupplot}

% add labels below
\foreach \i/\txt in {1/SW,2/SL,3/PW,4/PL}
  \node [below] at (iris c\i r1.south west) {\txt};


% draw the lines
% this dataset has three groups of fifty rows each, hence the start/stop values
\foreach[
 evaluate=\j as \START using int(\j*50),
 evaluate=\j as \STOP using int((\j+1)*50-1),
  ] \j/\clr in {0/blue,1/red,2/green}
{
\foreach \i in {\START,...,\STOP}
   \draw [color=\clr,opacity=0.5] (sl\i) -- (sw\i) -- (pl\i) -- (pw\i);
}

\end{tikzpicture}
\end{document}
|improve this answer|||||

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.