Function Repository Resource:

ParallelCoordinatesPlot

Source Notebook

Plots high-dimensional datasets across parallel axes

Contributed by: Anton Antonov

ResourceFunction["ParallelCoordinatesPlot"][mat]

visualizes mat with a parallel coordinates plot.

ResourceFunction["ParallelCoordinatesPlot"][mat,cols]

labels the plot axes that correspond to data columns with cols.

ResourceFunction["ParallelCoordinatesPlot"][mat,cols,ranges]

determines the span of each data column in the plot by the two-column matrix ranges.

Details and Options

Parallel coordinates are a way of visualizing and analyzing high-dimensional datasets.
Each data point is plotted over a parallel grid of axes; each axis corresponds to a data dimension.
ResourceFunction["ParallelCoordinatesPlot"] takes all options of Graphics.
The following additional options can be used:
"AxesOrder"Automaticorder of the axes (data columns)
"Colors"Automaticcolors to be used for multiple data
"Direction""Horizontal"direction of the plot
"LabelsOffset"Automaticoffset for the axes labels
"PlotAxesGrid"Truewhether to plot the axes grid
PlotStyleAutomaticplot style
The value of the option "AxesOrder" can be a list of integers, Automatic or Random.
If the first argument is an association of matrices, then the option "Colors" specifies the coloring of the rows of the different matrices. The value of "Colors" can be an association of matrix keys to colors, a string identifying a color function, Automatic or Random.
ResourceFunction["ParallelCoordinatesPlot"] is similar to ListLinePlot, but allows the specification of data column ranges and order, as well as the visualization of data subgroups.

Examples

Basic Examples (2) 

Visualize the rows of a matrix:

In[1]:=
SeedRandom[2]
ResourceFunction["ParallelCoordinatesPlot"][
 RandomReal[{-10, 20}, {12, 5}]]
Out[2]=

Visualize the rows of matrices in an association:

In[3]:=
aMats = AssociationThread[Range[3], Partition[Sort@RandomReal[{-1, 4}, {30, 5}], 10]];
ResourceFunction["ParallelCoordinatesPlot"][aMats]
Out[4]=

Scope (5) 

Matrices (3) 

Visualize the rows of a matrix using column names:

In[5]:=
SeedRandom[2]
ResourceFunction["ParallelCoordinatesPlot"][
 RandomReal[{-10, 20}, {8, 7}], RandomWord[7], PlotStyle -> Orange]
Out[6]=

Visualize the rows of a matrix using column names and axes ranges:

In[7]:=
SeedRandom[2]
ResourceFunction["ParallelCoordinatesPlot"][
 RandomReal[{-10, 20}, {8, 7}], RandomWord[7], Transpose[{Round@RandomReal[{-30, -10}, 7], Round@RandomReal[{10, 100}, 7]}], PlotStyle -> Orange]
Out[8]=

Visualize without labels for the data columns' names:

In[9]:=
SeedRandom[2]
ResourceFunction["ParallelCoordinatesPlot"][
 RandomReal[{-10, 20}, {8, 7}], None, PlotStyle -> Orange]
Out[10]=

Associations of matrices (2) 

Here is an association of matrices with the same number of columns and different number of rows:

In[11]:=
SeedRandom[7]
aRData = Association@
   MapThread[
    RandomWord[] -> RandomVariate[
       NormalDistribution[#1, Abs[#1]/2], {#2, 5}] &, {{2, -1, 4}, RandomInteger[{20, 30}, 3]}];
MatrixPlot /@ aRData
Out[13]=
In[14]:=
Dimensions /@ aRData
Out[14]=

Here we visualize the multidimensional data of each matrix using a (combined) parallel coordinates plot:

In[15]:=
ResourceFunction["ParallelCoordinatesPlot"][aRData, ImageSize -> Large]
Out[15]=

Options (6) 

AxesOrder (1) 

Changing the axes order (the order of the data columns) might produce more informative plots:

In[16]:=
SeedRandom[4]
mat = RandomReal[{0, 10}, {20, 4}];
colNames = Style[#, Red, Bold] & /@ MapIndexed[ToString[#2[[1]]] <> "-" <> #1 &, RandomWord[Length@mat[[1]]]];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][mat, colNames, "AxesOrder" -> i, PlotStyle -> Gray, ImageSize -> Medium]}, {i, {Automatic, Random, {1, 3, 2, 4}}}], {"AxesOrder", "Plot"}], Dividers -> All,
  FrameStyle -> LightGray]
Out[9]=

Colors (1) 

The option "Colors" specifies the coloring of the rows of the different matrices:

In[17]:=
SeedRandom[8]
aMats = Association[
   RandomWord[] -> RandomVariate[NormalDistribution[#, #/4], {12, 5}] & /@ {2, 4, 8}];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][aMats, "Colors" -> i, ImageSize -> Medium]}, {i, {Automatic, Random, AssociationThread[Keys[aMats], ColorData["BrightBands"] /@ Rescale[Range[Length@aMats]]], "WatermelonColors"}}], {"Colors", "Plot"}], Dividers -> All, FrameStyle -> LightGray]
Out[7]=

Direction (1) 

For some data, it is easier to see patterns through vertical parallel coordinates plots:

In[18]:=
SeedRandom[5]
aMats = Association[# -> RandomVariate[NormalDistribution[#, #/2], {12, 4}] & /@ {2, 6, 4}];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][aMats, "Direction" -> i, ImageSize -> Medium]}, {i, {"Horizontal", "Vertical"}}], {"Direction", "Plot"}], Dividers -> All, FrameStyle -> LightGray]
Out[7]=

LabelsOffset (1) 

The option "LabelsOffset" allows tweaking of the axes labels' locations:

In[19]:=
SeedRandom[1]
mat = RandomReal[{-10, 20}, {4, 7}];
colNames = Style[#, Red, Bold] & /@ RandomWord[Length@mat[[1]]];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][mat, colNames, "LabelsOffset" -> i, PlotStyle -> Gray, ImageSize -> Medium]}, {i, {Automatic, 1, 4}}], {"LabelsOffset", "Plot"}], Dividers -> All, FrameStyle -> LightGray]
Out[9]=

PlotAxesGrid (1) 

If the value of the option "PlotAxesGrid" is False, then no axes grid is plotted:

In[20]:=
SeedRandom[1]
mat = RandomReal[{-10, 20}, {4, 7}];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][mat, "PlotAxesGrid" -> i, PlotStyle -> Gray, ImageSize -> Medium]}, {i, {True, False}}], {"PlotAxesGrid", "Plot"}], Dividers -> All, FrameStyle -> LightGray]
Out[7]=

PlotStyle (1) 

The option PlotStyle can be used to specify how the lines corresponding to the data elements are drawn:

In[21]:=
SeedRandom[9]
mat = RandomReal[{0, 10}, {16, 6}];
Grid[Prepend[
  Table[{i, ResourceFunction["ParallelCoordinatesPlot"][mat, PlotStyle -> i, ImageSize -> Medium]}, {i, {Automatic, {Thick, Orange}, {Dashed, Blue}}}], {PlotStyle, "Plot"}], Dividers -> All, FrameStyle -> LightGray]
Out[7]=

Applications (3) 

Get the "FisherIris" dataset:

In[22]:=
data = ExampleData[{"Statistics", "FisherIris"}];
colNames = ExampleData[{"Statistics", "FisherIris"}, "ColumnDescriptions"]
Out[23]=

Split the iris data into groups defined by the species column (which is the last column):

In[24]:=
aData = GroupBy[data, #[[-1]] &, #[[All, 1 ;; -2]] &];
Keys[aData]
Out[25]=

Use ParallelCoordinatesPlot to visualize the differences between subsets of data:

In[26]:=
ResourceFunction["ParallelCoordinatesPlot"][aData, Style[#, FontSize -> 16] & /@ Most[colNames], "Colors" -> "Rainbow", "AxesOrder" -> Random, Direction -> "Horizontal", ImageSize -> Large]
Out[26]=

Properties and Relations (1) 

ParallelCoordinatesPlot can be seen as an extension of ListLinePlot:

In[27]:=
SeedRandom[1]
mat = RandomReal[{-10, 20}, {12, 7}];
ListLinePlot[mat, PlotLabel -> "ListLinePlot"]
Out[29]=
In[30]:=
ResourceFunction["ParallelCoordinatesPlot"][mat, PlotStyle -> Gray, PlotLabel -> "ParallelCoordinatesPlot"]
Out[30]=

Possible Issues (1) 

If the first argument is an association of matrices, then the third argument (for the axes ranges) is always taken to be Automatic:

In[31]:=
ResourceFunction["ParallelCoordinatesPlot"][aRData, Automatic, "blah"]
Out[31]=

Neat Examples (1) 

Make a grid of parallel coordinates plots using the "FisherIris" dataset:

In[32]:=
SeedRandom[12];
data = ExampleData[{"Statistics", "FisherIris"}];
colNames = ExampleData[{"Statistics", "FisherIris"}, "ColumnDescriptions"];
aData = GroupBy[data, #[[-1]] &, #[[All, 1 ;; -2]] &];
grs = Table[
   ResourceFunction["ParallelCoordinatesPlot"][aData, Most[colNames], "Colors" -> Random, "AxesOrder" -> Random, Direction -> dir, ImageSize -> Medium], {dir, {"Horizontal", "Vertical"}}, {m, 3}];
Grid[grs, Alignment -> Left, Dividers -> All]
Out[5]=

Publisher

Anton Antonov

Version History

  • 1.0.0 – 15 October 2020

Source Metadata

Related Resources

License Information